Closed zhouzi closed 7 years ago
That's interesting, I didn't know firebase could compare object. I will add tests and fix that later today.
ps: currently, it treats ==
and ===
both as strict equality.
@Zhouzi Do you have a test I can try in the simulator?
I tries with:
data:
{"foo": {"a": 1, "b": 2}}
Rules:
{"rules": {"bar": {".write": "root.child('foo').val() === newData.val()"}}}
Simulation: Write "/bar" with {"a": 1, "b": 2}
It fails for me.
I just spent some time giving it another try and apparently I was mistaking. I debugged the code that led me to think that Firebase was performing a deep equality check and I was whether testing it wrong or using the admin SDK (which doesn't care about rules).
Sorry for bothering 😞
No problem. AFAIK, the only way to compare random object properties is with:
{
"rules": {
"bar": {
".write": "newData.exists()",
"$key": {
".validate": "newData.parent().parent().child('foo').child($key).val() == newData.val()"
}
}
}
}
When using
==
, Firebase performs a deep equality check.For example, if you wanted to ensure equality of two objects stored in different points of the JSON tree:
With this rule, Firebase will disallow creating objects that are not strictly equal.
Though it's not really documented: https://firebase.google.com/docs/reference/security/database/#equals