问题描述
我需要为一个名为测试用例"的子集合创建一个存储规则.由于Firestore规则不是用JavaScript编写的,因此我似乎无法在匹配后获得路径来毫无错误地接受空格.
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.
我已经尝试了引号,转义字符的反斜杠,以及将整个路径都用引号引起来.我没有在Firestore文档中或堆栈溢出中找到任何与此相关的内容.
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();
}
}
推荐答案
根据火力支持:
要解决此问题,您可以使用%20在安全规则内对空格进行编码.因此规则将是:
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.
这篇关于带路径中空格的Firestore安全规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!