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

Override target attributes in anchors in templates. #1587

Merged
merged 1 commit into from
Jan 26, 2016

Conversation

dvoytenko
Copy link
Contributor

Related to #1572.

} else if (!target) {
// TODO(dvoytenko, #1572): Change this once sanitization of targets is
// addressed. The most correct value is probably _top.
updatedTarget = '_blank';
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you have these conditionals confused in the comment: anything without a target should behave as target="_top" and anything with should temporarily be assigned to target="_blank".

PS. can you swap the conditionals to avoid the !target-else double negation?

if (target == '_top' || target == '_blank') {
  //...
} else if (target) {
  // ...
} else {
  // ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed double negation.

However, the conditions themselves are correct - the default temporarily is "_blank". We will have to switch it later (or completely remove this code) once the sanitization issue is addressed. It's documented in the comments.


// TODO(dvoytenko, #1572): This code should be unnecessary after
// sanitization issue has been addressed.
anchor.setAttribute('target', '_blank');
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this'll also open new windows for fragment urls like #top and #section-1, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is ok since we process hash navigation separately in document-click.js. My hope, also, is to remove the whole thing once we resolve sanitizer problems.

@jridgewell
Copy link
Contributor

One last comment, then LTGM.

dvoytenko added a commit that referenced this pull request Jan 26, 2016
Override target attributes in anchors in templates.
@dvoytenko dvoytenko merged commit 2e7be5a into ampproject:master Jan 26, 2016
@dvoytenko dvoytenko deleted the templ-target branch January 26, 2016 23:08
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.

3 participants