Skip to content

Commit

Permalink
Fix breaking preprocessors' directives when parsing attributes (#171)
Browse files Browse the repository at this point in the history
Co-authored-by: Christian Bewernitz <coder@karfau.de>
  • Loading branch information
yeegor and karfau committed Jan 25, 2021
1 parent baa67f5 commit fd47c51
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/dom.js
Expand Up @@ -1064,7 +1064,7 @@ function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){
}
return;
case ATTRIBUTE_NODE:
return buf.push(' ',node.name,'="',node.value.replace(/[<&"]/g,_xmlEncoder),'"');
return buf.push(' ',node.name,'="',node.value.replace(/[&"]/g,_xmlEncoder),'"');
case TEXT_NODE:
/**
* The ampersand character (&) and the left angle bracket (<) must not appear in their literal form,
Expand Down
6 changes: 3 additions & 3 deletions test/html/__snapshots__/normalize.test.js.snap
Expand Up @@ -40,13 +40,13 @@ Object {
exports[`html normalizer <div test="a<b&&a< c && a>d"></div> 1`] = `
Object {
"actual": "<div test=\\"a&lt;b&amp;&amp;a&lt; c &amp;&amp; a>d\\" xmlns=\\"http://www.w3.org/1999/xhtml\\"></div>",
"actual": "<div test=\\"a<b&amp;&amp;a< c &amp;&amp; a>d\\" xmlns=\\"http://www.w3.org/1999/xhtml\\"></div>",
}
`;

exports[`html normalizer <div test="alert('<br/>')"/> 1`] = `
Object {
"actual": "<div test=\\"alert('&lt;br/>')\\" xmlns=\\"http://www.w3.org/1999/xhtml\\"></div>",
"actual": "<div test=\\"alert('<br/>')\\" xmlns=\\"http://www.w3.org/1999/xhtml\\"></div>",
}
`;

Expand Down Expand Up @@ -86,7 +86,7 @@ Object {

exports[`html normalizer <html test="a<b && a>b && '&amp;&&'"/> 1`] = `
Object {
"actual": "<html test=\\"a&lt;b &amp;&amp; a>b &amp;&amp; '&amp;&amp;&amp;'\\" xmlns=\\"http://www.w3.org/1999/xhtml\\"></html>",
"actual": "<html test=\\"a<b &amp;&amp; a>b &amp;&amp; '&amp;&amp;&amp;'\\" xmlns=\\"http://www.w3.org/1999/xhtml\\"></html>",
}
`;

Expand Down
2 changes: 1 addition & 1 deletion test/parse/__snapshots__/locator.test.js.snap
Expand Up @@ -2,7 +2,7 @@

exports[`DOMLocator attribute position 1`] = `
Object {
"actual": "<html xmlns=\\"http://www.w3.org/1999/xhtml\\"><body title=\\"1&lt;2\\"><table></table>&lt;;test</body></html>",
"actual": "<html xmlns=\\"http://www.w3.org/1999/xhtml\\"><body title=\\"1<2\\"><table></table>&lt;;test</body></html>",
}
`;

Expand Down
4 changes: 2 additions & 2 deletions test/parse/__snapshots__/simple.test.js.snap
Expand Up @@ -12,7 +12,7 @@ Object {

exports[`parse simple 1`] = `
Object {
"actual": "<html xmlns=\\"http://www.w3.org/1999/xhtml\\"><body title=\\"1&lt;2\\"></body></html>",
"actual": "<html xmlns=\\"http://www.w3.org/1999/xhtml\\"><body title=\\"1<2\\"></body></html>",
}
`;

Expand Down Expand Up @@ -49,6 +49,6 @@ Object {
exports[`parse wrong closing tag 1`] = `
Object {
"actual": "<html xmlns=\\"http://www.w3.org/1999/xhtml\\"><body title=\\"1&lt;2\\"><table></table>&lt;;test</body></html>",
"actual": "<html xmlns=\\"http://www.w3.org/1999/xhtml\\"><body title=\\"1<2\\"><table></table>&lt;;test</body></html>",
}
`;
2 changes: 1 addition & 1 deletion test/xmltest/__snapshots__/not-wf.test.js.snap
Expand Up @@ -112,7 +112,7 @@ Object {
exports[`xmltest/not-wellformed standalone should match 014.xml with snapshot 1`] = `
Object {
"actual": "<doc a1=\\"&lt;foo>\\"/>",
"actual": "<doc a1=\\"<foo>\\"/>",
}
`;
Expand Down
2 changes: 1 addition & 1 deletion test/xmltest/__snapshots__/valid.test.js.snap
Expand Up @@ -293,7 +293,7 @@ Object {
exports[`xmltest/valid standalone should match 040.xml with snapshot 1`] = `
Object {
"actual": "<doc a1=\\"&quot;&lt;&amp;>'\\"/>",
"actual": "<doc a1=\\"&quot;<&amp;>'\\"/>",
"expected": "<doc a1=\\"&quot;&lt;&amp;&gt;'\\"></doc>",
}
`;
Expand Down

0 comments on commit fd47c51

Please sign in to comment.