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

fix: prevent document parsing from decoding entities within HTML document #133

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;');
});
});