路径中有空格的 Firestore 安全规则

tem*_*eva 1 firebase firebase-security firebase-authentication google-cloud-firestore

我需要为名为“测试用例”的子集合创建一个 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();
      }
    }
Run Code Online (Sandbox Code Playgroud)

小智 5

根据火力基地支援:

要解决此问题,您可以使用 %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(); 
} 
} 
} 
Run Code Online (Sandbox Code Playgroud)

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

  • @JeevaCanessane 如果文档有“+”,那么安全规则将需要“+”的URL编码值,即“%2B”。https://www.urlencoder.org/ 是查找其他 URL 编码值的有用工具。 (2认同)