Skip to content

Keep the closing bracket out of a link Reddit makes from an address - #124

Merged
paskal merged 1 commit into
masterfrom
reddit-link-bracket
Dec 5, 2026
Merged

paskal merged 1 commit into
masterfrom
reddit-link-bracket

Conversation

@paskal

@paskal paskal commented Dec 5, 2026

Copy link
Copy Markdown
Member

Previously, a Reddit post that wrote a bare address in brackets, such as [https://example.com/a/], came out with the closing bracket inside the link. Reddit's own page links the address that way, and the site handler kept the link as it was, so the link's address ended in an extra ].

After this change, cleanFragment, which cleans post and comment text for Reddit and Hacker News, trims such links (trimAutolink):

  • It applies only to a link that holds nothing but its own absolute http or https address as text, the shape a site's autolinker makes.
  • A trailing ., ,, ;, :, ! or ?, and a ) or ] that the address does not open, move out of the link's address and text and follow the link as text. The example above becomes [<a href="https://example.com/a/">https://example.com/a/</a>].
  • Balanced parentheses and brackets stay, as in https://en.wikipedia.org/wiki/Go_(game) or http://[::1].
  • A link with text of its own, a relative link and a link with another scheme keep their address.

Verified:

  • TestCleanFragmentAutolink covers the bracketed, parenthesised and trailing-comma cases and the links that must stay as they are. Its four trimming cases and the Reddit case of TestSiteGolden fail with the trim removed. The Hacker News golden output is unchanged.
  • Lint and race tests pass, and the Docker image builds.

A Reddit post that writes a bare address in brackets, as
"[https://example.com/a/]", comes from Reddit's page with the closing
bracket inside the link, so the link's address ended in an extra "]".

When a link in a post or comment holds nothing but its own http or https
address as text, the punctuation that ends the address now follows the
link as text: a trailing full stop, comma, semicolon, colon, exclamation
or question mark, and a closing parenthesis or bracket the address does
not open. A link with text of its own keeps its address. Hacker News
text goes through the same cleaning.
@paskal
paskal requested a balanced review from Copilot December 5, 2026 21:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@paskal
paskal requested a balanced review from Copilot December 5, 2026 21:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@paskal
paskal merged commit 44eb40b into master Dec 5, 2026
2 checks passed
@paskal
paskal deleted the reddit-link-bracket branch December 5, 2026 21:59
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.

2 participants