Skip to content

Commit 96af875

Browse files
committed
[Fix] no-unknown-property: use a better regex to avoid a crash
Fixes #3666
1 parent b95a059 commit 96af875

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1717
* [`jsx-no-leaked-render`]: preserve RHS parens for multiline jsx elements while fixing ([#3623][] @akulsr0)
1818
* [`jsx-key`]: detect conditional returns ([#3630][] @yialo)
1919
* [`jsx-newline`]: prevent a crash when `allowMultilines ([#3633][] @ljharb)
20+
* [`no-unknown-property`]: use a better regex to avoid a crash ([#3666][] @ljharb @SCH227)
2021

2122
### Changed
2223
* [Refactor] `propTypes`: extract type params to var ([#3634][] @HenryBrown0)
@@ -25,6 +26,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
2526
* [Refactor] [`jsx-props-no-multi-spaces`]: extract type parameters to var ([#3634][] @HenryBrown0)
2627
* [Docs] [`jsx-key`]: fix correct example ([#3656][] @developer-bandi)
2728

29+
[#3666]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3666
2830
[#3662]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3662
2931
[#3656]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3656
3032
[#3654]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3654

lib/rules/no-unknown-property.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ function normalizeAttributeCase(name) {
429429
* @returns {boolean} Result
430430
*/
431431
function isValidDataAttribute(name) {
432-
return /^data(-[^:]*)*$/.test(name) && !/^data-xml/i.test(name);
432+
return !/^data-xml/i.test(name) && /^data(-?[^:]*)$/.test(name);
433433
}
434434

435435
/**

tests/lib/rules/no-unknown-property.js

+23
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ ruleTester.run('no-unknown-property', rule, {
162162
// fbs
163163
{ code: '<fbs desc="foo" doNotExtract />;' },
164164
{ code: '<math displaystyle="true" />;' },
165+
{
166+
code: `
167+
<div className="App" data-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash="customValue">
168+
Hello, world!
169+
</div>
170+
`,
171+
},
165172
]),
166173
invalid: parsers.all([
167174
{
@@ -645,5 +652,21 @@ ruleTester.run('no-unknown-property', rule, {
645652
},
646653
],
647654
},
655+
{
656+
code: `
657+
<div className="App" data-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash:c="customValue">
658+
Hello, world!
659+
</div>
660+
`,
661+
features: ['no-ts'],
662+
errors: [
663+
{
664+
messageId: 'unknownProp',
665+
data: {
666+
name: 'data-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash-crash:c',
667+
},
668+
},
669+
],
670+
},
648671
]),
649672
});

0 commit comments

Comments
 (0)