FirebaseExtended / bolt

Bolt Compiler (Firebase Security and Modeling)
Apache License 2.0
897 stars 107 forks source link

'.val()' not added when prior() inside square brackets. #252

Open siddhantkothari opened 4 years ago

siddhantkothari commented 4 years ago

A simple reproducible example showing the bug:

.bolt file: path /test/{x} is String{ validate() { this.parent()[prior(this)] == x } } .json file produced: { "rules": { "test": { "$x": { ".validate": "(newData.isString() && newData.parent().child(data).val() == $x)" } } } } .json file expected: { "rules": { "test": { "$x": { ".validate": "(newData.isString() && newData.parent().child(data.val()).val() == $x)" } } } } Inside the child function data.val() should be present. When I remove the prior(), the result is newData.val() as expected.

Nickk4 commented 8 months ago

To add a similar issue where .val() is not added:

path /{project_uuid} {
  read() {
    projectMatch(this.parent_uuid)
  }
}

function projectMatch(parent_uuid) {
  return (
    auth != null &&
    parent_uuid != null &&
    auth[parent_uuid] != null
  );
}

The last line compiles into:

auth[data.child('parent_uuid')] != null

instead of

auth[data.child('parent_uuid').val()] != null