Repository navigation
fix(search): report an empty regex match at a row's end one past its last cell - #884
Merged
Merged
Conversation
…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>
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.
What & why
searchable_rowmaps 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. Sofind_all_matches($)on six columns gave(0, 5, "")onabcdef,(1, 2, "")onaband(2, 5, "")onabcd中, and the result could not tell "the last character's column" from "the column after the text".findnever reports the second column of a wide character, and the rustdoc of theregeximpl says the column is mapped back "exactly asfinddoes".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 columnsfind_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, perrust-toolchain.toml), on top ofdc5f2ee: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.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, "")].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.shandcheck-no-ai-attribution.shonupstream/main..HEAD-> OK.Not run locally: the other feature combinations of the
testandclippyjobs, the MSRV and Windows-target checks,cargo doc,cargo deny,cargo-semver-checks,zizmorandcheck-readme-links.sh. The change touches no public item.Checklist
cargo fmt --allandcargo clippy --workspace --all-targets --all-featuresare cleangit commit -s) — see CONTRIBUTING.md §5CHANGELOG.mdupdated under[Unreleased](user-facing changes only)cargo insta review, not blind-accepted