Skip to content

urlize: escape text once and isolate mail linking - #383

Open
codexagents wants to merge 1 commit into
flosch:masterfrom
tokenmaxed:sandbox@ns1029703/upstream-urlize
Open

urlize: escape text once and isolate mail linking#383
codexagents wants to merge 1 commit into
flosch:masterfrom
tokenmaxed:sandbox@ns1029703/upstream-urlize

Conversation

@codexagents

Copy link
Copy Markdown

Summary

  • escape ordinary text runs as well as URL anchor text when urlize autoescape is enabled
  • truncate using the unescaped URL/mail address so HTML entities do not move the visible limit
  • run email linking only over text between URL matches, never over anchors generated by the URL pass

Why

The current two-pass replacement first emits URL anchors and then applies the email regexp to that generated HTML. An email-shaped substring inside a URL can therefore be replaced inside the new href. In addition, autoescape only covers matched URL titles; unmatched input is returned inside an AsSafeValue unchanged.

Building the result from alternating text and URL runs makes provenance explicit. Each raw text/title run is escaped at most once, and generated markup is never scanned as input.

Verification

  • go test ./...
  • go test -race ./...
  • go vet ./...

@sonarqubecloud

Copy link
Copy Markdown

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.

1 participant