Skip to content

Commit

Permalink
[Fix] jsx-no-target-blank: avoid a crash with a non-string literal
Browse files Browse the repository at this point in the history
Fixes #2851.
  • Loading branch information
ljharb committed Nov 6, 2020
1 parent 5f6350a commit edbbd79
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -13,7 +13,9 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
### Fixed
* [`display-name`]/component detection: avoid a crash on anonymous components ([#2840][] @ljharb)
* [`prop-types`]: function in class that returns a component causes false warning in typescript ([#2843][] @SyMind)
* [`jsx-no-target-blank`]: avoid a crash with a non-string literal ([#2851][] @ljharb)

[#2851]: https://github.com/yannickcr/eslint-plugin-react/issues/2851
[#2843]: https://github.com/yannickcr/eslint-plugin-react/pull/2843
[#2840]: https://github.com/yannickcr/eslint-plugin-react/issues/2840
[#2835]: https://github.com/yannickcr/eslint-plugin-react/pull/2835
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-no-target-blank.js
Expand Up @@ -23,7 +23,7 @@ function isTargetBlank(attr) {
attr.value.type === 'JSXExpressionContainer'
&& attr.value.expression
&& attr.value.expression.value
&& attr.value.expression.value.toLowerCase() === '_blank'
&& String(attr.value.expression.value).toLowerCase() === '_blank'
));
}

Expand Down
3 changes: 3 additions & 0 deletions tests/lib/rules/jsx-no-target-blank.js
Expand Up @@ -89,6 +89,9 @@ ruleTester.run('jsx-no-target-blank', rule, {
{
code: '<a href="foobar" target="_blank" rel="noopener"></a>',
options: [{allowReferrer: true}]
},
{
code: '<a target={3} />'
}
],
invalid: [{
Expand Down

0 comments on commit edbbd79

Please sign in to comment.