Cloud Storage split() 示例错误的 Firebase 安全规则
Firebase Security Rules for Cloud Storage split() Example Error
我正在尝试遵循 Firebase 云存储安全规则参考中列出的示例:
https://firebase.google.com/docs/reference/security/storage/
我将 split()
的示例复制并粘贴到我的存储规则中,它不会 compile/let 我保存:
Splits a string according to a provided regular expression and returns a list of strings. Uses Google RE2 syntax.
// Allow files named "file.*" to be uploaded
match /{fileName} {
allow write: if fileName.split('.*\..*')[0] == 'file'
}
我得到的错误:
Unexpected '.'.
在我的生活中,我无法获得提供给 运行 的示例代码,也无法进行更改并使 Regex 按预期工作。
有人对 Allow files named "file.*" to be uploaded
有什么建议吗?
规则中似乎缺少 \
。试试这个:
// Allow files named "file.*" to be uploaded
match /{fileName} {
allow write: if fileName.split('.*\..*')[0] == 'file'
}
通常在使用正则表达式时,首先要检查反斜杠。不同的系统使用反斜杠进行转义,有时(例如此处)您需要对它们进行双重转义。
文档有误。改用它 ('\.'):
// Allow files named "file.*" to be uploaded
match /{fileName} {
allow write: if fileName.split('\.')[0] == 'file'
}
我正在尝试遵循 Firebase 云存储安全规则参考中列出的示例:
https://firebase.google.com/docs/reference/security/storage/
我将 split()
的示例复制并粘贴到我的存储规则中,它不会 compile/let 我保存:
Splits a string according to a provided regular expression and returns a list of strings. Uses Google RE2 syntax.
// Allow files named "file.*" to be uploaded
match /{fileName} {
allow write: if fileName.split('.*\..*')[0] == 'file'
}
我得到的错误:
Unexpected '.'.
在我的生活中,我无法获得提供给 运行 的示例代码,也无法进行更改并使 Regex 按预期工作。
有人对 Allow files named "file.*" to be uploaded
有什么建议吗?
规则中似乎缺少 \
。试试这个:
// Allow files named "file.*" to be uploaded
match /{fileName} {
allow write: if fileName.split('.*\..*')[0] == 'file'
}
通常在使用正则表达式时,首先要检查反斜杠。不同的系统使用反斜杠进行转义,有时(例如此处)您需要对它们进行双重转义。
文档有误。改用它 ('\.'):
// Allow files named "file.*" to be uploaded
match /{fileName} {
allow write: if fileName.split('\.')[0] == 'file'
}