-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
handle anchor tags with no href in noopener audit #1238
Conversation
${anchor.rel ? ` rel="${anchor.rel}"` : ''}>... | ||
</a>` | ||
url: '<a' + | ||
(anchor.href !== '' ? ` href="${anchor.href}"` : '') + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the template string here rendered fine in the html report but took up five lines per link in the pretty print report, e.g.
<a
href="http://get.grubhub.com/?referer=seamless.com"
target="_blank"
>...
</a>
The logic also got overly complicated for dropping the href line if it was ''
(since it would leave a blank line), so easier to just turn this into string concatenation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps an array + array.join can help you make it prettier for the eyes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it hopefully reads better with @ebidel's suggestion to make the conditionals all the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor nits
@@ -82,6 +82,8 @@ | |||
<template id="noopener-links-tmpl"> | |||
<!-- FAIL - does not use rel="noopener" to open external link --> | |||
<a href="https://www.google.com/" target="_blank">external link</a> | |||
<!-- FAIL - does not use rel="noopener" but no href attribute --> | |||
<a target="_blank">external link</a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add a comment here or in the audit that when no href is given, the browser has a '' by default. Thats why you do the '' check I suppose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the suggested changes.
I think it's safe to include href-less links in the report. It's a common thing to do in SPAs and I think we can safely assume a target="_blank"
is intended to go off-site.
url: '<a' + | ||
(anchor.href !== '' ? ` href="${anchor.href}"` : '') + | ||
(anchor.target ? ` target="${anchor.target}"` : '') + | ||
(anchor.rel ? ` rel="${anchor.rel}"` : '') + '>...' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we should just just drop the ...</a>
. It doesn't add much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
${anchor.rel ? ` rel="${anchor.rel}"` : ''}>... | ||
</a>` | ||
url: '<a' + | ||
(anchor.href !== '' ? ` href="${anchor.href}"` : '') + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(anchor.href ? \` href="${anchor.href}"\` : '') +
to be consistent with the others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well I was going to say what if it was like 0
or something else falsy, but that doesn't make sense :)
addresses #1233. See that issue for details on why we still include anchors with no
href
in the audit results.We might want to leave that open as the reporting of links with no href leaves something to be desired (e.g. the first link in the seamless example ends up as
<a target="_blank" >... </a>
in the URLs dropdown in the report).Not sure how to make it easier to identify the links in question without starting to write formatters for all the major frameworks, though.