Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
fix: prevent document parsing from decoding entities within HTML docu…
Browse files Browse the repository at this point in the history
…ment (#133)

Decoding the entities within HTML content can lead to undoing escapes
  • Loading branch information
josephperrott authored Aug 4, 2023
1 parent c663a24 commit 7757902
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/critters/src/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function buildCache(container) {
* @param {String} html HTML to parse into a Document instance
*/
export function createDocument(html) {
const document = /** @type {HTMLDocument} */ (parseDocument(html));
const document = /** @type {HTMLDocument} */ (parseDocument(html, {decodeEntities: false}));

defineProperties(document, DocumentExtensions);

Expand Down
15 changes: 15 additions & 0 deletions packages/critters/test/critters.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,19 @@ describe('Critters', () => {
expect(result).toMatch('<link rel="stylesheet" href="/style.css">');
expect(result).toMatch('<title>$title</title>');
});

test('Does not decode entities in HTML document', async () => {
const critters = new Critters({
path: '/'
});
critters.readFile = (filename) => assets[filename];
const result = await critters.process(trim`
<html>
<body>
&lt;h1&gt;Hello World!&lt;/h1&gt;
</body>
</html>
`);
expect(result).toMatch('&lt;h1&gt;Hello World!&lt;/h1&gt;');
});
});

0 comments on commit 7757902

Please # to comment.