0

I have a text string that includes an escape sequence like \u00f1. When I ingest in JS and try to append the string to a div, it's literally rendering \u00f1 rather than ñ.

I've tried en/decodeURIComponent and un/escape() to no avail.

Any tricks on how to get the escape sequence rendering the correct UTF-8 character in JS?

P.S. The page is already encoded in UTF-8

ssilas777
  • 9,476
  • 4
  • 43
  • 66
Scott Graph
  • 507
  • 5
  • 11

1 Answers1

0

The only sane solution is to make sure HTML is properly encoded. Trying to "decode" content may easily bring cross-site-scripting (XSS) issues (incomplete attempt to fix it is likely reason why you see over-encoded text).

Otherwise you can try to decode it several times (for good measure) by using innerHTML and content properties...

Alexei Levenkov
  • 96,782
  • 12
  • 124
  • 169