Skip to content

Commit e5b9f35

Browse files
committed
[Fix] no-invalid-html-attribute: avoid crash on spread props
Fixes #3126
1 parent e672316 commit e5b9f35

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
2222
* [`prop-types`], `propTypes`: add forwardRef<>, ForwardRefRenderFunction<> prop-types ([#3112] @vedadeepta)
2323
* [`no-typos`]: prevent a crash when using private methods (@ljharb)
2424
* [`destructuring-assignment`], component detection: improve component detection ([#3122] @vedadeepta)
25+
* [`no-invalid-html-attribute`]: avoid crash on spread props ([#3126] @ljharb)
2526

2627
### Changed
2728
* [Tests] test on the new babel eslint parser ([#3113] @ljharb)
28-
* [Docs] [`jsx-no-target-blank`]: adjust options description ([#3214] @gebsh)
29+
* [Docs] [`jsx-no-target-blank`]: adjust options description ([#3124] @gebsh)
2930

30-
[#3214]: https://github.com/yannickcr/eslint-plugin-react/pull/3214
31+
[#3126]: https://github.com/yannickcr/eslint-plugin-react/issue/3126
32+
[#3124]: https://github.com/yannickcr/eslint-plugin-react/pull/3124
3133
[#3122]: https://github.com/yannickcr/eslint-plugin-react/pull/3122
3234
[#3113]: https://github.com/yannickcr/eslint-plugin-react/pull/3113
3335
[#3112]: https://github.com/yannickcr/eslint-plugin-react/pull/3112

lib/rules/no-invalid-html-attribute.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ function checkCreateProps(context, node, attribute) {
416416
}
417417

418418
for (const prop of propsArg.properties) {
419-
if (prop.key.type !== 'Identifier') {
419+
if (!prop.key || prop.key.type !== 'Identifier') {
420420
// eslint-disable-next-line no-continue
421421
continue; // cannot check computed keys
422422
}

tests/lib/rules/no-invalid-html-attribute.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,14 @@ ruleTester.run('no-invalid-html-attribute', rule, {
203203
{ code: '<a rel={{a: "noreferrer"}["b"]}></a>' },
204204
{ code: '<Foo rel></Foo>' },
205205
{ code: 'React.createElement("Foo", { rel: true })' },
206+
{
207+
code: `
208+
React.createElement('a', {
209+
...rest,
210+
href: to,
211+
})
212+
`,
213+
},
206214
],
207215
invalid: [
208216
{

0 commit comments

Comments
 (0)