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

uirules: add a rule to add anchors to URL-shaped text #7

Merged
merged 4 commits into from
Aug 15, 2023

Conversation

creachadair
Copy link
Member

Signed-off-by: M. J. Fromberger fromberger@tailscale.com

Signed-off-by: M. J. Fromberger <fromberger@tailscale.com>
Value: regexp.MustCompile(`^https?://\S+$`),
Apply: func(col, s string, _ []string) any {
if _, err := url.Parse(s); err == nil {
return template.HTML(fmt.Sprintf(`<a href="%s" referrerpolicy=no-referrer rel=noopener>`, s))

Choose a reason for hiding this comment

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

I'm concerned that %s might include a "><script>... from some user data. Am I misunderstanding template.HTML?

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 could in general, but in this case we are only plugging it in if a URL parser accepts it as valid, which should rule out that sort of shenanigan.

Copy link
Member Author

@creachadair creachadair Aug 15, 2023

Choose a reason for hiding this comment

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

I made it render the URL's string explicitly, so we can be sure we are getting proper escapes.

@creachadair creachadair merged commit e5c925c into main Aug 15, 2023
1 check passed
@creachadair creachadair deleted the mjf/decorate-links branch August 15, 2023 18: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.

None yet

2 participants