Skip to content

Instantly share code, notes, and snippets.

@onel0p3z
Last active December 16, 2015 08:49
Show Gist options
  • Save onel0p3z/5408960 to your computer and use it in GitHub Desktop.
Save onel0p3z/5408960 to your computer and use it in GitHub Desktop.
Simple HTML encoding for JSON-like objects when used in a query string (GET) UPDATE: I just found out of escape() ... just a bit late ...
function htmlEscape(str) {
return String(str)
.replace(/{/g, '%7B')
.replace(/"/g, '%22')
.replace(/:/g, '%3A')
.replace(/}/g, '&7D')
.replace(/,/g, '%2C')
.replace(/@/g, '%40')
.replace(/\\/g, '')
.split(' ').join('+')
//https://coderwall.com/p/jk5f3q
//.toLowerCase().replace(/^\s+|\s+$/g,"").replace(/[\s]+|\t|\n|\r/g, "-");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment