RomainVialard / FirebaseApp

Google Apps Script binding for Firebase Realtime Database
Apache License 2.0
116 stars 30 forks source link

fixed number in string converted to variable of type number #2

Closed grzegorz-it closed 6 years ago

grzegorz-it commented 7 years ago

It's important to do not change variable type while creating request. For example when you change type string to number you'll get error when searching by key because firebase do not allow keys to be numbers, it allow only strings.

JeanRemiDelteil commented 6 years ago

The current code does not change the key type, it encodes the optional query parameters if it is not a number.

I will close the PR for now, but you have a sample test that demonstrate an issue with the actual code, we will consider it again.

JeanRemiDelteil commented 6 years ago

Indeed this can happens for some ordering properties: var r = base.getData("", { orderBy:"code", equalTo: code }); for var code = "12345"; // no results var code = "03456"; // Error: Constraint index field must be a JSON primitive

grzegorz-it commented 6 years ago

Exactly, if you put to equalTo a string containg number, this string will be converted to number and firebase will throw error:

getData("fbMessengerUsers", {"orderBy": "$key", "equalTo": "123"});

ERROR: "Key index passed non-string bound"

If you will use fix based on my pull request the string "123" will be not converted to number and it will work.

This is related to issue #3

JeanRemiDelteil commented 6 years ago

I've has some problems with the merging, this will be fixed tomorrow.