Skip to content

Commit edbbd79

Browse files
committed
[Fix] jsx-no-target-blank: avoid a crash with a non-string literal
Fixes #2851.
1 parent 5f6350a commit edbbd79

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
1313
### Fixed
1414
* [`display-name`]/component detection: avoid a crash on anonymous components ([#2840][] @ljharb)
1515
* [`prop-types`]: function in class that returns a component causes false warning in typescript ([#2843][] @SyMind)
16+
* [`jsx-no-target-blank`]: avoid a crash with a non-string literal ([#2851][] @ljharb)
1617

18+
[#2851]: https://github.com/yannickcr/eslint-plugin-react/issues/2851
1719
[#2843]: https://github.com/yannickcr/eslint-plugin-react/pull/2843
1820
[#2840]: https://github.com/yannickcr/eslint-plugin-react/issues/2840
1921
[#2835]: https://github.com/yannickcr/eslint-plugin-react/pull/2835

lib/rules/jsx-no-target-blank.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function isTargetBlank(attr) {
2323
attr.value.type === 'JSXExpressionContainer'
2424
&& attr.value.expression
2525
&& attr.value.expression.value
26-
&& attr.value.expression.value.toLowerCase() === '_blank'
26+
&& String(attr.value.expression.value).toLowerCase() === '_blank'
2727
));
2828
}
2929

tests/lib/rules/jsx-no-target-blank.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ ruleTester.run('jsx-no-target-blank', rule, {
8989
{
9090
code: '<a href="foobar" target="_blank" rel="noopener"></a>',
9191
options: [{allowReferrer: true}]
92+
},
93+
{
94+
code: '<a target={3} />'
9295
}
9396
],
9497
invalid: [{

0 commit comments

Comments
 (0)