Skip to content

Commit

Permalink
deeals protocol-relative URLs are external
Browse files Browse the repository at this point in the history
  • Loading branch information
gfx committed May 22, 2017
1 parent 7c45509 commit 664e5df
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/rules/jsx-no-target-blank.js
Expand Up @@ -41,7 +41,7 @@ module.exports = {
continue;
}
if (attr.name.name === 'href') {
if (attr.value.type === 'Literal' && !/^\w+:/.test(attr.value.value)) {
if (attr.value.type === 'Literal' && !/^(?:\w+:|\/\/)/.test(attr.value.value)) {
// it's safe because it is not an external link (i.e. doesn't start with a protocol)
return;
}
Expand Down
10 changes: 8 additions & 2 deletions tests/lib/rules/jsx-no-target-blank.js
Expand Up @@ -62,6 +62,12 @@ ruleTester.run('jsx-no-target-blank', rule, {
errors: [{
message: 'Using target="_blank" without rel="noopener noreferrer" is a security risk:' +
' see https://mathiasbynens.github.io/rel-noopener'
}]}
]
}]
}, {
code: '<a target="_blank" href="//example.com"></a>',
errors: [{
message: 'Using target="_blank" without rel="noopener noreferrer" is a security risk:' +
' see https://mathiasbynens.github.io/rel-noopener'
}]
}]
});

0 comments on commit 664e5df

Please sign in to comment.