diff --git a/CHANGELOG.md b/CHANGELOG.md index a7f3fcca62..a3404276dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange * [`jsx-no-leaked-render`]: preserve RHS parens for multiline jsx elements while fixing ([#3623][] @akulsr0) * [`jsx-key`]: detect conditional returns ([#3630][] @yialo) * [`jsx-newline`]: prevent a crash when `allowMultilines ([#3633][] @ljharb) +* [`no-unknown-property`]: use a better regex to avoid a crash ([#3666][] @ljharb @SCH227) ### Changed * [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 * [Refactor] [`jsx-props-no-multi-spaces`]: extract type parameters to var ([#3634][] @HenryBrown0) * [Docs] [`jsx-key`]: fix correct example ([#3656][] @developer-bandi) +[#3666]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3666 [#3662]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3662 [#3656]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3656 [#3654]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3654 diff --git a/lib/rules/no-unknown-property.js b/lib/rules/no-unknown-property.js index 51ec84572f..2e77f2898b 100644 --- a/lib/rules/no-unknown-property.js +++ b/lib/rules/no-unknown-property.js @@ -429,7 +429,7 @@ function normalizeAttributeCase(name) { * @returns {boolean} Result */ function isValidDataAttribute(name) { - return /^data(-[^:]*)*$/.test(name) && !/^data-xml/i.test(name); + return !/^data-xml/i.test(name) && /^data(-?[^:]*)$/.test(name); } /** diff --git a/tests/lib/rules/no-unknown-property.js b/tests/lib/rules/no-unknown-property.js index 0f4fbbebc1..3c20feebd4 100644 --- a/tests/lib/rules/no-unknown-property.js +++ b/tests/lib/rules/no-unknown-property.js @@ -162,6 +162,13 @@ ruleTester.run('no-unknown-property', rule, { // fbs { code: ';' }, { code: ';' }, + { + code: ` +
+ Hello, world! +
+ `, + }, ]), invalid: parsers.all([ { @@ -645,5 +652,21 @@ ruleTester.run('no-unknown-property', rule, { }, ], }, + { + code: ` +
+ Hello, world! +
+ `, + features: ['no-ts'], + errors: [ + { + messageId: 'unknownProp', + data: { + 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', + }, + }, + ], + }, ]), });