-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTML entities in text nodes returned as real HTML #11
Comments
Related StackOverflow answers that explains why this happens: text nodeValue containing HTML entity |
The simplest approach might be to escape ampersands in text passed to the converter:
|
I used one weird trick to escape required symbols: var tempEl = document.createElement('div');
function escapeSpecialChars(value) {
// Uses this One Weird Trick to escape text - Raw text inserted as textContent
// will have its escaped version in innerHTML.
tempEl.textContent = value;
return tempEl.innerHTML;
}
escapeSpecialCharacters('<'); // < Although I just realised this won't work exactly right in Node.js where I use JSDom, so I'll have to move stuff around a bit. |
The fix works great in browser. Are the past couple fixes worthy of a minor version release or a patch release? |
Yeah I think I'll do a patch release, just want to wait a few days and see Regards, On Sat, Jan 10, 2015 at 12:13 PM, Ross Allen [email protected]
|
When a TextNode is encountered, HTML entities inside it are returned as HTML rather than the HTML entity. This is problematic for the use of
<
and>
in particular because the tags they wrap are then interpreted as real tags.For example:
The encoded symbols are returned as the symbols themselves, which eventually throws an error in Esprima because it encounters an unclosed tag.
This is expected and documented behavior of TextNodes and their
data
attribute, and it seems the way to get around it is to escape the characters differently before inserting the content into a real DOM node.The text was updated successfully, but these errors were encountered: