Last active
November 17, 2016 14:19
-
-
Save motss/aae177f7a249db653e00e34214e51038 to your computer and use it in GitHub Desktop.
strict encodeURIComponent for Firebase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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