Skip to content

Commit

Permalink
fix: Ignore href=javascript:.* for rel=noopener audit
Browse files Browse the repository at this point in the history
  • Loading branch information
karanjthakkar committed Oct 16, 2017
1 parent 04b685f commit e425d30
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class ExternalAnchorsUseRelNoopenerAudit extends Audit {
return true;
}
})
.filter(anchor => {
// Ignore href's that do not redirect to a new url
return !/javascript:.*/.test(anchor.href);
})
.map(anchor => {
return {
href: anchor.href || 'Unknown',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,15 @@ describe('External anchors use rel="noopener"', () => {
assert.equal(auditResult.details.items.length, 3);
assert.ok(auditResult.debugString, 'includes debugString');
});

it('does not fail for links with javascript in href attribute', () => {
const auditResult = ExternalAnchorsAudit.audit({
AnchorsWithNoRelNoopener: [
{href: 'javascript:void(0)'},
],
URL: {finalUrl: URL},
});
assert.equal(auditResult.rawValue, true);
assert.equal(auditResult.details.items.length, 0);
});
});

0 comments on commit e425d30

Please sign in to comment.