Fix file-link parser capturing trailing sentence period for .md paths (Closes #11477)
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:
654be7f1Strip trailing '.' from file-link candidate paths — adds.toSUFFIXES_TO_REMOVEsofoo.md.resolves tofoo.mdon the fallback path and the markdown classifier sees the correct extension. Addresses AC #1 (Editor/Viewer toggle appears).6ca44367Match POSIX highlight-range behaviour on Windows for trailing '.' — addresses AC #2 (highlight-range parity). On POSIX, the fallback path shrinksend_pointbysuffix.len()when the stripped form resolves; on Windows that branch is never reached because the NT kernel transparently normalizesfoo.md.→foo.mdand 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 shrunkend_point) when both resolve.
Three follow-up commits addressing Oz's review feedback:
8621a072Skip verbatim paths in strip_trailing_dot; strip exactly one dot — adds the\\?\verbatim-path guard tostrip_trailing_dotinapp/src/util/file.rsso its behavior matches the highlight-range branch inlink_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).e943fe9bTighten link_detection test helper range to match real grid ranges — fixes the test helpermake_possible_pathto build an inclusive range ending atpath.len() - 1(the index of the last character) rather thanpath.len()(one past the end); re-derivesexpected_end_colin the Windows highlight-parity test accordingly so the assertion accurately encodes the shrink invariant.7769d15dTest 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 likefoo.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 resolvedabsolute_pathinstead. Adds a Windows-onlyverbatim_path_guard_predicateunit 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_parityandverbatim_path_guard_predicateadded; fulllink_detectionsuite (13 tests) green - [x] New
strip_trailing_dotunit tests (4) added inapp/src/util/file.rs; fullutil::filesuite (31 tests) green on Windows - [x] Clippy clean with
cargo clippy -p warp --lib --tests -- -D warnings - [x]
cargo fmt --check -p warpclean - [x] Manual smoke-test on Windows in
warp-ossrelease 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]
mastermerged 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
could i see a video of before and after please
@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
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
/oz-review
Addressed the three concerns from the previous review:
- Concern 1 (verbatim path conflation):
strip_trailing_dotinapp/src/util/file.rsnow skips\?\-prefixed verbatim paths so its behavior matches the highlight-range branch inlink_detection.rs— see commit8621a072. 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_pathhelper now builds an inclusive range ending atpath.len() - 1(the index of the last character) rather thanpath.len()(one past the end);expected_end_colincompute_valid_paths_windows_highlight_range_parityis re-derived accordingly so the assertion accurately encodes the shrink invariant — see commite943fe9b. - 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
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
/oz-review
Addressed both concerns from the previous review:
-
Concern 1 (verbatim guard checked token instead of resolved path): commit
7769d15dchanges the highlight-parity guard inlink_detection.rsto test the resolvedabsolute_pathfor the\?\prefix rather than the captured token. A relative token likefoo.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-onlyverbatim_path_guard_predicateunit test verifies the predicate.Defense-in-depth note: the verbatim case is structurally unreachable on current call sites because
fs::metadatareturnsNonefor\?\...\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 fallbackSUFFIXES_TO_REMOVEloop handles it correctly. The guard is retained as defense-in-depth against future changes toabsolute_path_if_validor 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
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
@zachlloyd Hi, is there anything needed from me on this PR?