Search code examples
regexfirebase-security

Regex in Firebase Storage Rule with .matches(), the regex in regex tools works, but in storage rules not


I'm trying to check if name of folder that user have to acess contains your uid in firebase storage rules. Only way that I know is with regex and .matches. But all attempts fails even with I test the regex in regexr.com.

The folder contains two uids, the user need your uid in the folder name for read and write.

chats/uid1-uid2/

I try:

chatName.matches("/"+request.auth.uid+"/"); and another regex tryed, but all fail. I don't know what to think anymore

How could I do the validation


Solution

  • Solved

    I did not know that fire rules (At least from the storage I knew), have short syntax to split string/array without methods, just array[index1:index2], like in python.

    So how the uid is allways fixed size, is just two splits for get uids of uid1-uid2 and compare if uid1 === uid or uid2 === uid