Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(audit): Ignore href=javascript:.* for rel=noopener audit #3574

Merged
merged 6 commits into from
Nov 17, 2017
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ class ExternalAnchorsUseRelNoopenerAudit extends Audit {
return true;
}
})
.filter(anchor => {
// Ignore href's that are not real links
return (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we could probably simplify this to !anchor.href || !anchor.href.toLowerCase().startsWith('javascript:')

anchor.href
? !anchor.href.toLowerCase().startsWith('javascript:')
: true
);
})
.map(anchor => {
return {
href: anchor.href || 'Unknown',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,16 @@ 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)'},
{href: 'JAVASCRIPT:void(0)'},
],
URL: {finalUrl: URL},
});
assert.equal(auditResult.rawValue, true);
assert.equal(auditResult.details.items.length, 0);
});
});