Skip to content

Commit 92e5c65

Browse files
Sebmasterdomenic
authored andcommitted
Let the parser handle deserializing html entities
1 parent e038aca commit 92e5c65

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

lib/jsdom/browser/htmltodom.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ function HtmlToDom(parser) {
6363
var parserInstance = new parser.Parser(handler, {
6464
xmlMode: isXML,
6565
lowerCaseTags: !isXML,
66-
lowerCaseAttributeNames: !isXML
66+
lowerCaseAttributeNames: !isXML,
67+
decodeEntities: true
6768
});
6869

6970
parserInstance.includeLocation = false;
@@ -175,10 +176,8 @@ function setChild(parent, node) {
175176
break;
176177

177178
case 'text':
178-
// Decode HTML entities if we're not inside a <script> or <style> tag:
179-
newNode = currentDocument.createTextNode(/^(?:script|style)$/i.test(parent.nodeName) ?
180-
node.data :
181-
HTMLDecode(node.data));
179+
// HTML entities should already be decoded by the parser, so no need to decode them
180+
newNode = currentDocument.createTextNode(node.data);
182181
break;
183182

184183
case 'comment':
@@ -198,7 +197,7 @@ function setChild(parent, node) {
198197
// catchin errors here helps with improperly escaped attributes
199198
// but properly fixing parent should (can only?) be done in the htmlparser itself
200199
try {
201-
newNode.setAttribute(c, HTMLDecode(node.attribs[c]));
200+
newNode.setAttribute(c, node.attribs[c]);
202201
} catch(e2) { /* noop */ }
203202
}
204203
}

0 commit comments

Comments
 (0)