Skip to content

Commit

Permalink
Merge pull request #1298 from jseminck/jsx-no-target-blank
Browse files Browse the repository at this point in the history
Fix crash in jsx-no-target-blank
  • Loading branch information
ljharb authored Jul 13, 2017
2 parents 75fb917 + 322afa4 commit 739ece1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rules/jsx-no-target-blank.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function isTargetBlank(attr) {
}

function hasExternalLink(element) {
return element.attributes.find(function (attr) {
return element.attributes.some(function (attr) {
return attr.name &&
attr.name.name === 'href' &&
attr.value.type === 'Literal' &&
Expand All @@ -25,7 +25,7 @@ function hasExternalLink(element) {

function hasSecureRel(element) {
return element.attributes.find(function (attr) {
if (attr.name.name === 'rel') {
if (attr.type === 'JSXAttribute' && attr.name.name === 'rel') {
const tags = attr.value && attr.value.type === 'Literal' && attr.value.value.toLowerCase().split(' ');
return tags && (tags.indexOf('noopener') >= 0 && tags.indexOf('noreferrer') >= 0);
}
Expand Down
1 change: 1 addition & 0 deletions tests/lib/rules/jsx-no-target-blank.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ruleTester.run('jsx-no-target-blank', rule, {
{code: '<a randomTag></a>'},
{code: '<a href="foobar" target="_blank" rel="noopener noreferrer"></a>'},
{code: '<a target="_blank" {...spreadProps} rel="noopener noreferrer"></a>'},
{code: '<a {...spreadProps} target="_blank" rel="noopener noreferrer" href="http://example.com">s</a>'},
{code: '<a target="_blank" rel="noopener noreferrer" {...spreadProps}></a>'},
{code: '<p target="_blank"></p>'},
{code: '<a href="foobar" target="_BLANK" rel="NOOPENER noreferrer"></a>'},
Expand Down

0 comments on commit 739ece1

Please sign in to comment.