Cloud Storage的Firebase安全规则split()示例错误 [英] Firebase Security Rules for Cloud Storage split() Example Error

查看:54
本文介绍了Cloud Storage的Firebase安全规则split()示例错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试遵循《 Firebase云存储参考安全规则》中列出的示例:

I'm trying to follow the examples laid out in the Firebase Security Rules for Cloud Storage Reference:

https://firebase.google.com/docs/reference/security/存储/

我复制&将split()的示例粘贴到我的存储规则中,它将不会编译/让我保存:

I copy & paste the example for split() into my Storage Rules and it won't compile/let me save:

根据提供的正则表达式分割字符串,并返回字符串列表.使用Google RE2语法.

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正常工作.

For the life of me, I can't get the example code provided to run, nor can I make changes and get Regex to work as expected.

有人对Allow files named "file.*" to be uploaded有什么建议吗?

推荐答案

规则似乎缺少\.试试这个:

There seems to be a \ missing in the rules. Try this:

// Allow files named "file.*" to be uploaded
match /{fileName} {
  allow write: if fileName.split('.*\\..*')[0] == 'file'
}

通常,在使用正则表达式时,首先要检查反斜杠.不同的系统使用反斜杠进行转义,有时(例如此处)您需要对它们进行两次转义.

In general when working with regular expressions, the backslashes are the first thing to check. Different systems use backslashes for escaping and sometimes (such as here) you'll need to double escape them.

这篇关于Cloud Storage的Firebase安全规则split()示例错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆