Firestore security rules with spaces in path

岁酱吖の 提交于 2019-12-06 13:30:51

问题


I need to create a firestore rule for a sub collection called "Test Cases". Since firestore rules aren't written in javascript, I can't seem to get the path after match to accept a space without an error.

I've tried quotes, backslashes for escape characters, and putting the whole path in quotes. I haven't found anything for this in the firestore documentation or on stack overflow.

How can I allow a spaces in the path after match, in the example below, in the path including "Test Cases"?

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();
      }
    }

回答1:


According to fire base support:

To fix this, you can encode the space within security rules using %20. So the rules would be:

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(); 
} 
} 
} 

I tried it and worked for me. Please give it a try and let us know if you have any issues. 



来源:https://stackoverflow.com/questions/50708145/firestore-security-rules-with-spaces-in-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!