Skip to content

Commit

Permalink
Merge pull request #388 from preactjs/spellcheck
Browse files Browse the repository at this point in the history
fix: wrong spellcheck attribute value
  • Loading branch information
marvinhagemeister authored Aug 15, 2024
2 parents b40944a + 4621fa3 commit 1754f99
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/young-avocados-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'preact-render-to-string': patch
---

Fix `spellCheck={false}` not rendering as `spellcheck="false"`
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,9 @@ function _renderToString(
}
} else if (HTML_LOWER_CASE.test(name)) {
name = name.toLowerCase();
if (name === 'spellcheck') {
v = '' + v;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const VOID_ELEMENTS = /^(?:area|base|br|col|embed|hr|img|input|link|meta|
export const UNSAFE_NAME = /[\s\n\\/='"\0<>]/;
export const NAMESPACE_REPLACE_REGEX = /^(xlink|xmlns|xml)([A-Z])/;
export const HTML_LOWER_CASE = /^accessK|^auto[A-Z]|^cell|^ch|^col|cont|cross|dateT|encT|form[A-Z]|frame|hrefL|inputM|maxL|minL|noV|playsI|popoverT|readO|rowS|spellC|src[A-Z]|tabI|useM|item[A-Z]/;
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/;
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|spel|text[^L]|transform|underline|unicode|units|^v[^i]|^w|^xH/;

// DOM properties that should NOT have "px" added when numeric
const ENCODED_ENTITIES = /["&<]/;
Expand Down
8 changes: 8 additions & 0 deletions test/render.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ describe('render', () => {
expect(rendered).to.equal(`<div data-checked="false"></div>`);
});

it('should support spellCheck', () => {
let rendered = render(<div spellCheck={false} />);
expect(rendered).to.equal(`<div spellcheck="false"></div>`);

rendered = render(<div spellCheck />);
expect(rendered).to.equal(`<div spellcheck="true"></div>`);
});

describe('attribute name sanitization', () => {
it('should omit attributes with invalid names', () => {
let rendered = render(
Expand Down

0 comments on commit 1754f99

Please sign in to comment.