Skip to content

Commit 664e5df

Browse files
committed
deeals protocol-relative URLs are external
1 parent 7c45509 commit 664e5df

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = {
4141
continue;
4242
}
4343
if (attr.name.name === 'href') {
44-
if (attr.value.type === 'Literal' && !/^\w+:/.test(attr.value.value)) {
44+
if (attr.value.type === 'Literal' && !/^(?:\w+:|\/\/)/.test(attr.value.value)) {
4545
// it's safe because it is not an external link (i.e. doesn't start with a protocol)
4646
return;
4747
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ ruleTester.run('jsx-no-target-blank', rule, {
6262
errors: [{
6363
message: 'Using target="_blank" without rel="noopener noreferrer" is a security risk:' +
6464
' see https://mathiasbynens.github.io/rel-noopener'
65-
}]}
66-
]
65+
}]
66+
}, {
67+
code: '<a target="_blank" href="//example.com"></a>',
68+
errors: [{
69+
message: 'Using target="_blank" without rel="noopener noreferrer" is a security risk:' +
70+
' see https://mathiasbynens.github.io/rel-noopener'
71+
}]
72+
}]
6773
});

0 commit comments

Comments
 (0)