0

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.

0

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

https://github.com/WebReflection/html-escaper

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.