fix: handle URLs with balanced parentheses in URL detection#152
Open
ericjypark wants to merge 2 commits into
Open
fix: handle URLs with balanced parentheses in URL detection#152ericjypark wants to merge 2 commits into
ericjypark wants to merge 2 commits into
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
diegosouzapw
added a commit
to diegosouzapw/ghostty-web
that referenced
this pull request
May 23, 2026
URLs containing parentheses — such as Wikipedia links like https://en.wikipedia.org/wiki/Rust_(programming_language) — were incorrectly truncated. The URL regex character class excluded `(` and `)`, so the match stopped at the first parenthesis. Additionally, TRAILING_PUNCTUATION unconditionally stripped `)`, breaking URLs where parentheses are part of the path. Fix: - Add `()` to the URL regex character class so parentheses are captured - Remove `)` from TRAILING_PUNCTUATION to preserve balanced parens - Add a balanced-paren stripping pass: only strip trailing `)` when the URL has more closes than opens (e.g. URL wrapped in surrounding parens) Adds four unit tests covering Wikipedia paths, wrapped URLs, multiple parenthesized path segments, and nested parentheses. Inspired-by: coder#152 Co-authored-by: eric-jy-park <2019147551@yonsei.ac.kr>
|
Hi @ericjypark! 👋 Your work on this PR inspired a commit in my fork diegosouzapw/ghostty-web. I'm working on OmniRoute, a project that provides free access to LLM models, and I'm planning to use ghostty-web as the terminal component there. Your work is part of what makes that possible. 🙏 Feel free to check it out — contributions and feedback are very welcome! |
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