fix: handle URLs with balanced parentheses in URL detection#152
Open
ericjypark wants to merge 2 commits intocoder:mainfrom
Open
fix: handle URLs with balanced parentheses in URL detection#152ericjypark wants to merge 2 commits intocoder:mainfrom
ericjypark wants to merge 2 commits intocoder:mainfrom
Conversation
URLs containing parentheses (e.g., Wikipedia links like https://en.wikipedia.org/wiki/Rust_(programming_language)) were truncated at the first `(` because the URL regex character class excluded parentheses, and TRAILING_PUNCTUATION unconditionally stripped `)`. - Add `()` to URL_REGEX character class - Remove `)` from TRAILING_PUNCTUATION to avoid stripping balanced parens - Add balanced-paren stripping: only strip trailing `)` when unbalanced - Add tests for Wikipedia URLs, nested parens, and wrapped URLs
kylecarbs
approved these changes
Apr 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
URLs containing parentheses — such as Wikipedia links like
https://en.wikipedia.org/wiki/Rust_(programming_language)— are incorrectly truncated. The URL regex character class excludes(and), so the match stops at the first parenthesis. Additionally,TRAILING_PUNCTUATIONunconditionally strips), breaking URLs where parentheses are part of the path.Fix
()to the URL regex character class so parentheses are captured)fromTRAILING_PUNCTUATIONto preserve balanced parens)when the URL has more close-parens than open-parens (handles the common case of a URL wrapped in prose parentheses like(see https://...))Test Plan
bun test lib/url-detection.test.ts— 24/24 pass (4 new tests for parens handling)biome check .— cleantsc --noEmit— clean'strips trailing parenthesis'with(see https://example.com)still passes