Skip to content

Instantly share code, notes, and snippets.

@motss
Last active November 17, 2016 14:19
Show Gist options
  • Save motss/aae177f7a249db653e00e34214e51038 to your computer and use it in GitHub Desktop.
Save motss/aae177f7a249db653e00e34214e51038 to your computer and use it in GitHub Desktop.
strict encodeURIComponent for Firebase
// Strict escaping symbols not accepting by Firebase.
// https://www.firebase.com/docs/web/guide/understanding-data.html#section-creating-references
// Data Limits - A child node's key cannot be longer than 768 bytes, nor deeper than 32 levels.
// It can include any unicode characters except for . $ # [ ] / and ASCII control characters 0-31 and 127.
function encodeURIComponentForFirebase(str) {
return encodeURIComponent(str).replace(/[\.\#\$\[\]]/g, function (c) {
return '%' + c.charCodeAt(0).toString(16);
});
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment