warp icon indicating copy to clipboard operation
warp copied to clipboard

Fix file-link parser capturing trailing sentence period for .md paths (Closes #11477)

Open cbeaulieu-gt opened this issue 6 months ago • 7 comments

Summary

Fixes #11477 — the file-link parser captured a trailing sentence period as part of .md paths, breaking the markdown viewer activation and making the visible link highlight inconsistent across platforms.

Two original commits, both scoped to app/src/terminal/view/link_detection.rs:

  • 654be7f1 Strip trailing '.' from file-link candidate paths — adds . to SUFFIXES_TO_REMOVE so foo.md. resolves to foo.md on the fallback path and the markdown classifier sees the correct extension. Addresses AC #1 (Editor/Viewer toggle appears).
  • 6ca44367 Match POSIX highlight-range behaviour on Windows for trailing '.' — addresses AC #2 (highlight-range parity). On POSIX, the fallback path shrinks end_point by suffix.len() when the stripped form resolves; on Windows that branch is never reached because the NT kernel transparently normalizes foo.md. → foo.md and the literal lookup at line 542 succeeds first. The fix adds a #[cfg(target_os = "windows")]-gated branch in the literal-lookup success arm: when the captured token ends in ., also try the stripped form and prefer it (with shrunk end_point) when both resolve.

Three follow-up commits addressing Oz's review feedback:

  • 8621a072 Skip verbatim paths in strip_trailing_dot; strip exactly one dot — adds the \\?\ verbatim-path guard to strip_trailing_dot in app/src/util/file.rs so its behavior matches the highlight-range branch in link_detection.rs; strips exactly one trailing . for symmetry; adds Windows-only unit tests (verbatim path passthrough, no-dot passthrough, single-dot strip, multi-dot strips only outermost).
  • e943fe9b Tighten link_detection test helper range to match real grid ranges — fixes the test helper make_possible_path to build an inclusive range ending at path.len() - 1 (the index of the last character) rather than path.len() (one past the end); re-derives expected_end_col in the Windows highlight-parity test accordingly so the assertion accurately encodes the shrink invariant.
  • 7769d15d Test resolved path, not captured token, for verbatim guard — fixes Oz's second-round concern that the highlight-parity guard checked the captured token for the \\?\ prefix rather than the resolved absolute path. A relative token like foo.md. joined against a \\?\C:\share\ working directory ends up in verbatim space without the token itself carrying the prefix — the new guard tests the resolved absolute_path instead. Adds a Windows-only verbatim_path_guard_predicate unit test.

Cross-platform parity

POSIX object code stays bit-for-bit identical — the new branch and its dependencies are excluded from Linux/macOS binaries by the cfg gate. The change is Windows-only by construction.

The \\?\ long-path prefix guard (!path.starts_with(r"\\?\")) is included in both the highlight-range branch and the strip_trailing_dot helper so the change is correct in the edge case where a Linux SMB server serves distinct foo.md and foo.md. files via a long-path-prefixed mount — that syntax bypasses Win32 normalization, so we must not conflate the two in that one case.

Verbatim-guard reachability (defense-in-depth note)

The \\?\ guard in the highlight-parity branch is defense-in-depth rather than load-bearing under current call sites. In practice, when the working directory is \\?\-prefixed verbatim space, fs::metadata("foo.md.") returns None because verbatim paths bypass NT trailing-period normalization. That means the literal-lookup Some(absolute_path) arm — which gates the highlight-parity branch — is never entered for the verbatim case today; the SUFFIXES_TO_REMOVE fallback path handles it instead (correctly, with shrunk end_point).

The guard is retained because it protects against future changes to absolute_path_if_valid or its callers that could make the success arm reachable in verbatim space (e.g. a future caching layer, a different resolution strategy, or a platform-quirk regression). The unit test (verbatim_path_guard_predicate) directly verifies the predicate semantics rather than attempting an end-to-end exercise, because the end-to-end path is structurally unreachable on current code.

Test plan

  • [x] Unit tests: compute_valid_paths_windows_highlight_range_parity and verbatim_path_guard_predicate added; full link_detection suite (13 tests) green
  • [x] New strip_trailing_dot unit tests (4) added in app/src/util/file.rs; full util::file suite (31 tests) green on Windows
  • [x] Clippy clean with cargo clippy -p warp --lib --tests -- -D warnings
  • [x] cargo fmt --check -p warp clean
  • [x] Manual smoke-test on Windows in warp-oss release build: case 2 (echo "Drafted at C:/Users/chris/warp-md-test.md.") opens with the Editor↔Viewer toggle present and the visible underline excludes the trailing .
  • [x] Before/after videos embedded below
  • [x] master merged into branch (2026-05-26)
  • [ ] Maintainer triage on #11477 — ready-to-implement (or equivalent) label applied before merge

Scope decision

This PR is scoped to the trailing-. case from #11477's acceptance criteria. The broader closing-punctuation set (,;:!?)]}>"') discussed in the original issue body is intentionally not included here; if maintainers want that expansion it should be a separate scope conversation / follow-up issue rather than folded in.

Before / After

Before (latest stable as of 2026-05-23):

https://github.com/user-attachments/assets/6af650c9-1f45-402b-8beb-9245ea287d07

After:

https://github.com/user-attachments/assets/0d9176ce-fb51-4850-a65d-6234049ff291

CHANGELOG-BUG-FIX: Fix file-link parser including a trailing sentence period in .md paths, which prevented the markdown Editor/Viewer toggle from appearing when a .md file path was followed by punctuation.


🤖 Generated by Claude Code on behalf of @cbeaulieu-gt

cbeaulieu-gt avatar May 22 '26 13:05 cbeaulieu-gt

could i see a video of before and after please

zachlloyd avatar May 23 '26 19:05 zachlloyd

@zachlloyd Sure. Here you go.

Before (latest stable as of 5/23/2026)

https://github.com/user-attachments/assets/6af650c9-1f45-402b-8beb-9245ea287d07

After

https://github.com/user-attachments/assets/0d9176ce-fb51-4850-a65d-6234049ff291

cbeaulieu-gt avatar May 24 '26 01:05 cbeaulieu-gt

@cbeaulieu-gt

I'm starting a first review of this pull request.

You can view the conversation on Warp.

I completed the review and no human review was requested for this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

warp-for-oss[bot] avatar May 26 '26 23:05 warp-for-oss[bot]

/oz-review

Addressed the three concerns from the previous review:

  • Concern 1 (verbatim path conflation): strip_trailing_dot in app/src/util/file.rs now skips \?\-prefixed verbatim paths so its behavior matches the highlight-range branch in link_detection.rs — see commit 8621a072. Added four Windows-only unit tests covering verbatim passthrough, no-dot passthrough, single-dot strip, and the multi-dot case (only the outermost dot is removed, matching the highlight branch's &path[..path.len()-1] semantics).
  • Concern 2 (test helper off-by-one range): the make_possible_path helper now builds an inclusive range ending at path.len() - 1 (the index of the last character) rather than path.len() (one past the end); expected_end_col in compute_valid_paths_windows_highlight_range_parity is re-derived accordingly so the assertion accurately encodes the shrink invariant — see commit e943fe9b.
  • Concern 3 (missing video): before/after videos were already posted in this comment on 2026-05-24, three days before the review.

Also merged master into the branch and added the CHANGELOG-BUG-FIX line to the PR body per CONTRIBUTING.md.

🤖 Generated by Claude Code on behalf of @cbeaulieu-gt

cbeaulieu-gt avatar May 26 '26 23:05 cbeaulieu-gt

@cbeaulieu-gt

I'm re-reviewing this pull request in response to a review request.

You can view the conversation on Warp.

I completed the review and no human review was requested for this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

warp-for-oss[bot] avatar May 26 '26 23:05 warp-for-oss[bot]

/oz-review

Addressed both concerns from the previous review:

  • Concern 1 (verbatim guard checked token instead of resolved path): commit 7769d15d changes the highlight-parity guard in link_detection.rs to test the resolved absolute_path for the \?\ prefix rather than the captured token. A relative token like foo.md. joined to a \?\C:\share\ working directory ends up in verbatim space without the token itself carrying the prefix — that's what the old token-level check missed. New Windows-only verbatim_path_guard_predicate unit test verifies the predicate.

    Defense-in-depth note: the verbatim case is structurally unreachable on current call sites because fs::metadata returns None for \?\...\foo.md. (verbatim paths bypass NT trailing-period normalization), so the literal-lookup success arm — which gates the highlight-parity branch — is never entered for that path. The fallback SUFFIXES_TO_REMOVE loop handles it correctly. The guard is retained as defense-in-depth against future changes to absolute_path_if_valid or its callers; this is now spelled out in the PR body under "Verbatim-guard reachability".

  • Concern 2 (visual artifact missing from PR description): the before/after videos are now embedded directly in the PR description under "Before / After".

🤖 Generated by Claude Code on behalf of @cbeaulieu-gt

cbeaulieu-gt avatar May 27 '26 00:05 cbeaulieu-gt

@cbeaulieu-gt

I'm re-reviewing this pull request in response to a review request.

You can view the conversation on Warp.

I completed the review and no human review was requested for this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

warp-for-oss[bot] avatar May 27 '26 00:05 warp-for-oss[bot]

@zachlloyd Hi, is there anything needed from me on this PR?

cbeaulieu-gt avatar Jun 02 '26 22:06 cbeaulieu-gt