Skip to content

fix(terminal): stop URL wrap detection swallowing the next line - #186

Merged
matej21 merged 1 commit into
mainfrom
fix/url-wrap-false-positive
Aug 18, 2026
Merged

fix(terminal): stop URL wrap detection swallowing the next line#186
matej21 merged 1 commit into
mainfrom
fix/url-wrap-false-positive

Conversation

@matej21

@matej21 matej21 commented Aug 17, 2026

Copy link
Copy Markdown
Member

Problem

Phase 2 of URL detection (links.rs) extends a URL onto the following row when a TUI wraps the line itself, i.e. without a WRAPLINE flag. Its "URL reaches the end of the visible content" guard compared the URL's end against the URL row's own trimmed length — trivially satisfied by every row that ends with a URL. From there the only thing standing between the URL and the next line was the weak-extension guard, which lets through any token containing a /.

Claude Code's PR output hit exactly that shape, so the branch name landed inside the link:

  https://github.com/org/repo/pull/4
  (docs/data-flow-findings-and-system-audit → main).

Detected text before the fix:

https://github.com/org/repo/pull/4(docs/data-flow-findings-and-system-audit

The whole branch name was underlined and clicking the link opened the wrong URL.

Fix

A mid-token wrap fills the row to the layout edge, so a continuation row can never be wider than the row it continues. In the case above the URL row ends at column 46 while the next row runs to 52 — proof that the break was a word break, not a wrap.

  • Reject the extension when the next row is wider than the URL's end column, using the same +3 tolerance the other guards use.
  • Track url_end_col across iterations so multi-row extensions compare against the row they actually continue.

Phase 1 (real WRAPLINE wraps) is untouched.

Tests

New regression test detect_url_not_extended_when_next_line_is_longer, built from the screenshot above.

cargo test -p okena-terminal → 173 passed, 0 failed. All existing wrap tests still pass, including detect_url_wrapped_tui_narrow_layout and detect_url_wrapped_with_trailing_text, which cover genuine TUI-wrapped URLs.

🤖 Generated with Claude Code

https://claude.ai/code/session_01JZXzxKAXvZc2RrjYWRAbMX

Phase 2 extends a URL onto the following row when a TUI wraps the line
itself (no WRAPLINE flag). Its "URL reaches the end of the content" guard
compared against the URL row's own trimmed length, which is satisfied by
every row that happens to end with a URL — so any continuation whose first
token contains a slash was absorbed.

Claude Code's PR output hit this: the branch name on the next line ended up
inside the link.

  https://github.com/org/repo/pull/4
  (docs/data-flow-findings-and-system-audit -> main).

A mid-token wrap fills the row to the layout edge, so a continuation row can
never be wider than the row it continues. Reject the extension when the next
row is wider (same +3 tolerance the other guards use), and track the URL's
end column across rows so later iterations compare against the right row.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JZXzxKAXvZc2RrjYWRAbMX
@matej21
matej21 merged commit 6c750fc into main Aug 18, 2026
10 checks passed
@matej21
matej21 deleted the fix/url-wrap-false-positive branch August 18, 2026 09:25
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