Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wrong spellcheck attribute value #388

Merged
merged 1 commit into from
Aug 15, 2024
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
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') {
Copy link
Member

@rschristian rschristian Aug 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that it needs to be done here, but I think there's at least a handful of attrs/props that could need (depending on use circumstances) to be preserved as falsey.

Might be something we need to add another regex constant for in the future.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good point. Let's keep out an eye for that.

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