Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions .changeset/quiet-dragons-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"preact-render-to-string": patch
---

fix: escape a single quote
5 changes: 4 additions & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const HTML_LOWER_CASE = /^accessK|^auto[A-Z]|^ch|^col|cont|cross|dateT|en
export const SVG_CAMEL_CASE = /^ac|^ali|arabic|basel|cap|clipPath$|clipRule$|color|dominant|enable|fill|flood|font|glyph[^R]|horiz|image|letter|lighting|marker[^WUH]|overline|panose|pointe|paint|rendering|shape|stop|strikethrough|stroke|text[^L]|transform|underline|unicode|units|^v[^i]|^w|^xH/;

// DOM properties that should NOT have "px" added when numeric
const ENCODED_ENTITIES = /["&<]/;
const ENCODED_ENTITIES = /["'&<]/;

/** @param {string} str */
export function encodeEntities(str) {
Expand All @@ -26,6 +26,9 @@ export function encodeEntities(str) {
case 38:
ch = '&amp;';
break;
case 39:
ch = '&#x27;';
break;
case 60:
ch = '&lt;';
break;
Expand Down
4 changes: 2 additions & 2 deletions test/render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ describe('render', () => {
});

it('should encode entities', () => {
let rendered = render(<div a={'"<>&'}>{'"<>&'}</div>),
expected = `<div a="&quot;&lt;>&amp;">&quot;&lt;>&amp;</div>`;
let rendered = render(<div a={'"\'<>&'}>{'"\'<>&'}</div>),
expected = `<div a="&quot;&#x27;&lt;>&amp;">&quot;&#x27;&lt;>&amp;</div>`;

expect(rendered).to.equal(expected);
});
Expand Down