You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
HTML entities in text nodes returned as real HTML #11
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.
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.
I used one weird trick to escape required symbols:
vartempEl=document.createElement('div');functionescapeSpecialChars(value){// Uses this One Weird Trick to escape text - Raw text inserted as textContent// will have its escaped version in innerHTML.tempEl.textContent=value;returntempEl.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.
Activity
ssorallen commentedon Jan 5, 2015
Related StackOverflow answers that explains why this happens: text nodeValue containing HTML entity
ssorallen commentedon Jan 10, 2015
The simplest approach might be to escape ampersands in text passed to the converter:
Daniel15 commentedon Jan 10, 2015
I used one weird trick to escape required symbols:
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.
Handle Node.js-like environment when creating temporary div. References
ssorallen commentedon Jan 10, 2015
The fix works great in browser.
Are the past couple fixes worthy of a minor version release or a patch release?
Daniel15 commentedon Jan 11, 2015
Yeah I think I'll do a patch release, just want to wait a few days and see
if any other small bug fixes come up.
Regards,
Daniel Lo Nigro
http://dan.cx/ | Twitter http://twitter.com/Daniel15 | Facebook
http://www.facebook.com/daaniel
On Sat, Jan 10, 2015 at 12:13 PM, Ross Allen notifications@github.com
wrote: