'How to allow emoji in Firestore rules, but disallow certain other special characters
I'm working on rules for a project. This project is an App developed with React-Native and the react-native-firebase library.
I already placed the main role-based rules and they work as expected.
I'm struggling when i work with string validation.
I'm trying to allow emojis using the matches() function from the firestore rules and so far i don't have the right solution.
Here is my code :
function ValidateUser(user) {
return (
///////
user.Description is string &&
user.Description.matches("[a-zA-Z0-9_ /some more characters/]+")
///////
)
}
The issue here is that I'm blocking any other characters which include unicode and emojis as well.
I found some solutions online like adding this to my regex :
\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]
Or even something like this :
\x00-\x7F or this one \xFFFF
None of them seems to work within the firestore rules.
So i tried to work the other way around and instead of allowing the characters i want, i tried to exclude those i don't want like so :
user.Description is string &&
user.Description.matches("[/unwanted special characters/]+") == false
It should allow an user to write only if this is false if none of this characters matches within the string. But for some reason it only works when there is only those characters in the string...
For example :
&#/ this won't allow the user to write
Hello&#/ this will allow the user to write while it shouldn't for my use-case.
Does anyone knows how to make it works ? Or how to allow emojis with firestore rules ?
Thanks for your help !
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
