English 中文(简体)
消防仓库备案规则——安全
原标题:Firestore Regex Rules - Security

I m试图利用管理机构对火灾储存规则进行电子邮件。

return request.resource.data.email.matches( /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i );

I pulled the regex directly from the Firebase documentation. https://firebase.google.com/docs/reference/security/database/regex

问题与我的电子邮件不相称。 我把它放入一个reg子检查器,似乎像<条码>/条码”那样。 它赢得了我的电子邮件,但如果我尝试,(这将在监管机构工作),那么火店规则就会犯错误。

firestore.rules:47:83 - ERROR Missing  match  keyword before path.
!  firestore.rules:47:83 - ERROR Unexpected  /. .
!  firestore.rules:47:85 - ERROR mismatched input  [  expecting { { ,  / , PATH_SEGMENT}
!  firestore.rules:47:95 - ERROR Unexpected  $ .
!  firestore.rules:47:96 - ERROR Missing  match  keyword before path.
!  firestore.rules:47:99 - ERROR mismatched input  )  expecting { { ,  / , PATH_SEGMENT}
!  firestore.rules:81:5 - ERROR Unexpected  allow .
!  firestore.rules:87:3 - ERROR Unexpected  } .

For reference the email I m testing against is

email: "[email protected]"
问题回答

你的规则存在一些问题。

  1. You re mixing literal RegEx syntax (starting/ending with /) with string-based syntax (enclosed in quotes).
  2. The /i at the end indicates you want a case-insensitive match, but I don t think that is supported in Firestore security rules.

最简单的解决办法是将其全部纳入一个插图,并仅添加<条码>a-z的幅度,以便允许上层和下级。

This works for me:

match /77724566/{doc} {
  allow write: 
    if request.resource.data.email.matches(
       ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$ 
    );
}

In here 77724566 is my collection name.





相关问题
Uncommon regular expressions [closed]

Recently I discovered two amazing regular expression features: ?: and ?!. I was curious of other neat regex features. So maybe you would like to share some tricky regular expressions.

regex to trap img tag, both versions

I need to remove image tags from text, so both versions of the tag: <img src="" ... ></img> <img src="" ... />

C++, Boost regex, replace value function of matched value?

Specifically, I have an array of strings called val, and want to replace all instances of "%{n}%" in the input with val[n]. More generally, I want the replace value to be a function of the match ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...

Is it possible to negate a regular expression search?

I m building a lexical analysis engine in c#. For the most part it is done and works quite well. One of the features of my lexer is that it allows any user to input their own regular expressions. This ...

regex for four-digit numbers (or "default")

I need a regex for four-digit numbers separated by comma ("default" can also be a value). Examples: 6755 3452,8767,9865,8766,3454 7678,9876 1234,9867,6876,9865 default Note: "default" ...

热门标签