Skip to content

Commit

Permalink
[Fix] no-invalid-html-attribute: avoid crash on spread props
Browse files Browse the repository at this point in the history
Fixes #3126
  • Loading branch information
ljharb committed Nov 7, 2021
1 parent e672316 commit e5b9f35
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Expand Up @@ -22,12 +22,14 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
* [`prop-types`], `propTypes`: add forwardRef<>, ForwardRefRenderFunction<> prop-types ([#3112] @vedadeepta)
* [`no-typos`]: prevent a crash when using private methods (@ljharb)
* [`destructuring-assignment`], component detection: improve component detection ([#3122] @vedadeepta)
* [`no-invalid-html-attribute`]: avoid crash on spread props ([#3126] @ljharb)

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

[#3214]: https://github.com/yannickcr/eslint-plugin-react/pull/3214
[#3126]: https://github.com/yannickcr/eslint-plugin-react/issue/3126
[#3124]: https://github.com/yannickcr/eslint-plugin-react/pull/3124
[#3122]: https://github.com/yannickcr/eslint-plugin-react/pull/3122
[#3113]: https://github.com/yannickcr/eslint-plugin-react/pull/3113
[#3112]: https://github.com/yannickcr/eslint-plugin-react/pull/3112
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-invalid-html-attribute.js
Expand Up @@ -416,7 +416,7 @@ function checkCreateProps(context, node, attribute) {
}

for (const prop of propsArg.properties) {
if (prop.key.type !== 'Identifier') {
if (!prop.key || prop.key.type !== 'Identifier') {
// eslint-disable-next-line no-continue
continue; // cannot check computed keys
}
Expand Down
8 changes: 8 additions & 0 deletions tests/lib/rules/no-invalid-html-attribute.js
Expand Up @@ -203,6 +203,14 @@ ruleTester.run('no-invalid-html-attribute', rule, {
{ code: '<a rel={{a: "noreferrer"}["b"]}></a>' },
{ code: '<Foo rel></Foo>' },
{ code: 'React.createElement("Foo", { rel: true })' },
{
code: `
React.createElement('a', {
...rest,
href: to,
})
`,
},
],
invalid: [
{
Expand Down

0 comments on commit e5b9f35

Please sign in to comment.