FirebaseExtended / bolt

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

Syntax error on compiled code when I have a field named "test" #199

Open 5argon opened 7 years ago

5argon commented 7 years ago

The following code passed the compilation but failed when deploying to Firebase

` path /userPrivate/{uid} is UserPrivateData { read() { auth.uid == uid } write() { auth.uid == uid } }

type UserPrivateData { playerId : String | Null, playerIdHash : Number | Null, formattedShortPlayerId : FormattedShortPlayerId | Null, playerData : String, test : Boolean | Null

create() { 
    //When creating you must have all of them. test is optional.
    (this.playerId != null &&
    this.playerIdHash != null &&
    this.formattedShortPlayerId != null &&
    this.playerData != null &&
    (this.test != null && this.test == true) || (this.test == null))
}

update() {
    //When updating only playerData is allowed.
    (this.playerId == null &&
    this.playerIdHash == null &&
    this.formattedShortPlayerId == null &&
    this.test == null &&
    this.playerData != null)
}
//Can't delete!
//Cannot use write() after using create update delete

}

path /userPublic/{formattedShortPlayerId} is UserPublicData { read() { auth != null } write() { formattedShortPlayerId.length == 12 && formattedShortPlayerId == root.userPrivate[auth.uid].formattedShortPlayerId } }

type UserPublicData { displayName : DisplayName | Null, iconForeground : String | Null, iconBackground : String | Null }

type FormattedShortPlayerId extends String { validate(){ this.length == 12 } }

type DisplayName extends String { validate(){ this.length <= 10 && this.length > 0 } } `

Error saving rules - Line 24: No such method/property 'test'.

Because it produces things like newData.val().test in the output.

However changing test to isTesting for example, solve the issue as the output correctly uses .child('isTesting').val()