1
votes

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
Is it actually possible to have a space in a path? - André Kool
Yes, it works well elsewhere. I have some documents who's names come from clients that have spaces, and they work fine when passed as a wildcard. It's just when I need to specify the specific path that I have a problem. - tempSeva

1 Answers

5
votes

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.