Skip to content

fix(search): report an empty regex match at a row's end one past its last cell - #884

Merged
vyncint merged 2 commits into
vyncint:mainfrom
KemalG-u:fix/empty-match-at-row-end
Dec 2, 2026
Merged

vyncint merged 2 commits into
vyncint:mainfrom
KemalG-u:fix/empty-match-at-row-end

Conversation

@KemalG-u

@KemalG-u KemalG-u commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

What & why

searchable_row maps each byte of a row's text to the column that produced it, then adds one extra entry so that an empty match at the very end of the text has a column to map to. That entry was the last column of the row (self.cols - 1). On a full row this is the column of the last character, and on a row ending in a wide character it is that character's second column, while a shorter row reported the column after its text. So find_all_matches($) on six columns gave (0, 5, "") on abcdef, (1, 2, "") on ab and (2, 5, "") on abcd中, and the result could not tell "the last character's column" from "the column after the text". find never reports the second column of a wide character, and the rustdoc of the regex impl says the column is mapped back "exactly as find does".

This takes the first option of the issue's fix sketch: the extra entry is now self.cols, the column a character printed next would start at, so an empty match at the end of a row is one past the last cell the text covers on every row. On six columns find_all_matches($) now gives (0, 6, ""), (1, 2, "") and (2, 6, "").

The reported column of such a match changes (only for a pattern that can match nothing at a row's end: $, \b, x* and the like), so there is a CHANGELOG entry under Fixed that says so and tells a test that expected the last cell's column to expect the column after it.

Fixes #853

Verification

Run in an isolated WSL box (rustc 1.100.1, stable, per rust-toolchain.toml), on top of dc5f2ee:

  • New test an_empty_match_at_the_end_of_a_row_is_one_past_its_last_cell (crates/termlens/tests/search.rs): a full row, a short row and a row ending in a wide character, on six columns.
  • Without the fix (test commit only): cargo test -p termlens --all-features --test search an_empty_match_at_the_end_of_a_row -> exit 101, left: [(0, 5, ""), (1, 2, ""), (2, 5, "")], right: [(0, 6, ""), (1, 2, ""), (2, 6, "")].
  • With the fix: same command -> exit 0, 1 passed.
  • cargo test --workspace --all-features -> exit 0 (991 passed, 0 failed, 6 ignored).
  • cargo test -p termlens --no-default-features --features regex -> exit 0 (835 passed, 0 failed, 5 ignored).
  • cargo fmt --all --check -> clean.
  • cargo clippy --workspace --all-targets --all-features -- -D warnings -> clean.
  • check-dco.sh and check-no-ai-attribution.sh on upstream/main..HEAD -> OK.

Not run locally: the other feature combinations of the test and clippy jobs, the MSRV and Windows-target checks, cargo doc, cargo deny, cargo-semver-checks, zizmor and check-readme-links.sh. The change touches no public item.

Checklist

  • Linked an issue (or explained above why none exists)
  • Tests added/updated for the change
  • cargo fmt --all and cargo clippy --workspace --all-targets --all-features are clean
  • All commits are signed off (git commit -s) — see CONTRIBUTING.md §5
  • No AI attribution trailers (no AI co-authors, "Generated with" footers, or bot identities) — see CONTRIBUTING.md §6
  • CHANGELOG.md updated under [Unreleased] (user-facing changes only)
  • Snapshot changes (if any) were reviewed with cargo insta review, not blind-accepted

…int#853)

Signed-off-by: Kemal (KarıncaAI) <176588062+KemalG-u@users.noreply.github.com>
…last cell (vyncint#853)

An empty match at the end of a row's text was mapped to the last column
of the row, which is a wide character's second column on a row ending in
one and the last character's column on a full row, while a short row
reported the column after its text. Map it to the column a character
printed next would start at, as the rule for every row. Closes vyncint#853.

Signed-off-by: Kemal (KarıncaAI) <176588062+KemalG-u@users.noreply.github.com>
@KemalG-u
KemalG-u requested a review from vyncint as a code owner December 2, 2026 09:23

@vyncint vyncint left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed: the extra map entry is reached only by an empty match at a row's end, so this changes exactly #853's case. CI is green. Thank you.

@vyncint
vyncint merged commit 3792aca into vyncint:main Dec 2, 2026
17 checks passed
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.

An empty regex match at the end of a full row reports the last column, even a wide character's second half

2 participants