RomainVialard / FirebaseApp

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

Issue with optQueryParameters when using a string with only digits #3

Closed thexs-dev closed 6 years ago

thexs-dev commented 6 years ago

I am using your FirebaseApp library as follow:

var r = base.getData("", { orderBy:"code", equalTo: code }); Assuming there are entries with the codes below, instead of valid results, I am getting these ...

var code = "12345"; // no results
var code = "03456"; // Error: Constraint index field must be a JSON primitive

The issue comes from line 249: if (isNaN(optQueryParameters[key]) && typeof optQueryParameters[key] !== 'boolean') { Because in both cases the function isNaN() returns false, considering both codes as numbers (that's how isNaN works as I understand), so it won't add the "" around the string value

But in this case the code values are strings with only digits, that can also have leading zeros

Is there a way to fix / workaround this situation?

Thanks in advance Fausto

p.s. I did a dirty hack to make it work, but not sure if it's the right approach

I just redefined isNaN as follow:

  FirebaseApp.isNaN = function(n) {
    return Number(parseFloat(n)) !== n;
  };

and it's working that way

JeanRemiDelteil commented 6 years ago

Fixed with #2