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

handle anchor tags with no href in noopener audit #1238

Merged
merged 1 commit into from
Dec 22, 2016
Merged

Conversation

brendankenny
Copy link
Member

@brendankenny brendankenny commented Dec 22, 2016

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.

${anchor.rel ? ` rel="${anchor.rel}"` : ''}>...
</a>`
url: '<a' +
(anchor.href !== '' ? ` href="${anchor.href}"` : '') +
Copy link
Member Author

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.

Copy link
Collaborator

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

Copy link
Member Author

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

Copy link
Collaborator

@wardpeet wardpeet left a 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>
Copy link
Collaborator

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

@ebidel ebidel left a 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}"` : '') + '>...' +
Copy link
Contributor

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.

Copy link
Member Author

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}"` : '') +
Copy link
Contributor

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.

Copy link
Member Author

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants