I am trying to escape all html characters with this function :

strNotes.replace(/&/g,'&amp;').replace(/'/g,'&apos;').replace(/"/g,'&quot;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/(?:\r\n|\r|\n)/g, '<br>');

But it seems like characters like &amp; and &gt; gets converted in some hex decimal format when uploaded in static resource. In chrome debug it is shown as strNotes.replace(/&/g,"&#38;").replace(/'/g,"&#39;").replace(/"/g,"&#34;").replace(/</g,"&#60;").replace(/>/g,"&#62;").replace(/(?:\r\n|\r|\n)/g, '<br>');

Now when we try to save case, we are not able to save it because it converts html characters wrongly. has anyone faced this issue till now?

Salesforce wants < or '>' to get saved in &gt; or &lt;, but not sure why javascript changes that to hexdecimals.

1 Answer 1


If anyone faces this issue in future, here is a library which handles all scenario:


Import this and every thing works fine. Usage : html.escape(strNotesEx) or html.unescape(strNotesEx)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .