var ref1 = new Firebase("http://gamma.firebase.com/myuser/123,456");
ref1.set("123,456");
var on1 = ref1.on("value", function(snapshot) {
console.log(snapshot.val());
});
// console logs 123,456
So naming with a comma works fine. But let’s say you want to pass around the url to the ref.
var url1 = ref1.toString();
console.log(url1);
// console logs http://gamma.firebase.com/myuser/123%2C456
The toString() function returns a version of the url with commas replaced by “%2C”. This would be fine if the URL were still useable.
var ref2 = new Firebase(url1);
var on2 = ref2.on("value", function(snapshot) {
console.log(snapshot.val());
});
// console logs null
Is this a bug, or is there a good reason why the user should have to do something like
var url1 = ref1.toString().replace(/%2C/g,",");
in order to get a useable Firebase URL?
Commas are allowed in Firebase keys. There is a list of restricted characters on our website though for future reference in our docs.
The issue here is that the toString() method is URL-encoding the urls. Our intention here is that this will make it easier to paste that URL in a browser and view it with our real-time debugger. I can see how this creates a problem though if you call toString and then try to create a new Firebase reference with that string.
We didn’t consider it a normal use case for someone to do that. Could you elaborate on why you are building new Firebase references using the toString method of another reference? We have “child()” and “parent()” functions to help you traverse your data.
We’re going to discuss internally if we want to change the way URLs are encoded in toString and may fix this in future versions.