Open alex-wilmer opened 6 years ago
May I work on this issue? Thinking of using regex to decode the special characters.
Yas! Go for it @owenip
Hey @mihok , @alex-wilmer , I am wondering how many special characters should be supported. Please see HTML named character References.
Current Approaches for most common special characters
function unescapeHtml(text) {
return text
.replace(/&/g, '&')
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, "\"")
.replace(/'/g, "'");
}
Isn't encodeURI
and decodeURI
sufficient for this?
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI
Not Escaped:
A-Z a-z 0-9 ; , / ? : @ & = + $ - _ . ! ~ * ' ( ) #
encodeURI
doesn't handle those characters.
Also stackOverflow api return named characters which could not be converted by decodeURI
questions with special characters need to be encoded:
responses with special characters need to be decoded: