FirebaseExtended / bolt

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

`this` and `prior(this)` are ignored in functions #177

Open bijoutrouvaille opened 8 years ago

bijoutrouvaille commented 8 years ago

An example test.bolt,

path /unchangeable1 {
  write() { isTheSame() }
}

path /unchangeable2 {
  write() { prior(this)==this }
}

isTheSame() { prior(this)==this }

renders to the following,

{
  "rules": {
    "unchangeable1": {
      ".write": "this == this"
    },
    "unchangeable2": {
      ".write": "data.val() == newData.val()"
    }
  }
}

Am I missing the idea or should unchangeable1 be rendered the same as unchangeable2?

mckoss commented 7 years ago

This should probably return an error at compile time. I think the issue is that the value of 'this' is defined inside a validation or write rule, but is not bound in the function.

To get around this, you can pass this as a parameter to your function instead.