【问题标题】:Firestore security rules with spaces in path路径中带有空格的 Firestore 安全规则
【发布时间】:2018-11-15 09:59:07
【问题描述】:

我需要为一个名为“测试用例”的子集合创建一个 Firestore 规则。由于firestore规则不是用javascript编写的,我似乎无法在匹配后获得路径来接受空格而不会出错。

我尝试了引号、转义字符的反斜杠以及将整个路径放在引号中。我在firestore文档或堆栈溢出中没有找到任何相关内容。

如何在匹配后的路径中允许空格,在下面的示例中,在包含“测试用例”的路径中?

service cloud.firestore {

  match /databases/{database}/documents {

    match /companies/{company} {
      allow read: if getUserCompany() == company || userHasAnyRole(['Super', 'Manager']);
      allow write: if getUserCompany() == company || userHasAnyRole(['Super', 'Manager']); 

      match /Test Cases/{tests} {
        allow read, write: if isSignedIn();
      }
    }

【问题讨论】:

  • 路径中真的可以有空格吗?
  • 是的,它在其他地方运行良好。我有一些文件的名字来自有空格的客户,当作为通配符传递时它们工作正常。只是当我需要指定具体路径的时候我有问题。

标签: firebase firebase-authentication google-cloud-firestore firebase-security


【解决方案1】:

根据火力基地支援:

要解决此问题,您可以使用 %20 对安全规则中的空间进行编码。所以规则是:

Service cloud.firestore { 

match /databases/{database}/documents { 

match /companies/{company} { 
allow read: if getUserCompany() == company || userHasAnyRole(['Super', 'Manager']); 
allow write: if getUserCompany() == company || userHasAnyRole(['Super', 'Manager']); 

match /Test%20Cases/{tests} {                      <------- 
allow read, write: if isSignedIn(); 
} 
} 
} 

我尝试过并为我工作。请试一试,如果您有任何问题,请告诉我们。

【讨论】:

  • 如果有“+”是什么情况?
  • @JeevaCanessane 如果文档有“+”,那么安全规则将需要“+”的 URL 编码值,即%2Burlencoder.org 是查找其他 URL 编码值的有用工具。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-01-10
  • 1970-01-01
  • 2018-09-01
  • 2018-10-19
  • 2019-07-05
  • 2016-07-29
  • 1970-01-01
相关资源
最近更新 更多