fix: avoid unicode filepath suffix panic#393
Open
tmdgusya wants to merge 2 commits intodmtrKovalenko:mainfrom
Open
fix: avoid unicode filepath suffix panic#393tmdgusya wants to merge 2 commits intodmtrKovalenko:mainfrom
tmdgusya wants to merge 2 commits intodmtrKovalenko:mainfrom
Conversation
dmtrKovalenko
approved these changes
Apr 19, 2026
Owner
|
@copilot resolve the merge conflicts in this pull request |
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.
Summary
path_ends_with_suffix()falseinstead of panicking when a byte-derived suffix offset lands inside a multibyte characterapply_constraints(Constraint::FilePath(...))Similar PR / duplicate check
I checked existing PRs before opening this:
fix: Unicode segmentation crash)Constraint::FilePath/path_ends_with_suffix()panic pathThis PR is intentionally narrow: it fixes the unchecked
path[start..]slice incrates/fff-core/src/constraints.rswithout changing matching semantics.Root cause
path_ends_with_suffix()computed:and then sliced with:
startis a byte offset, not guaranteed to be a UTF-8 char boundary. For Unicode filenames, a non-matching suffix can makestartland inside a multibyte codepoint, which panics before constraint filtering can returnfalse.Fix
Use
path.get(start..)instead of unchecked indexing:startis not a valid char boundary, returnfalse/boundary behaviorVerification
I avoided using any user-specific filename in tests and instead used synthetic Unicode fixture names.
Reproduction guard added
New tests in
crates/fff-core/src/constraints.rs:test_path_ends_with_suffix_does_not_panic_on_unicode_suffixtest_apply_constraints_file_path_with_unicode_suffixtest_path_contains_segment_does_not_panic_on_unicode_segmentThe important regression case uses a synthetic filename such as:
data/유니코드_파일_테스트.csvand a deliberately non-matching suffix that would previously place the byte offset in the middle of a multibyte character.
Commands run
cargo test -p fff-search constraints::tests -- --nocaptureResult
All constraint tests pass locally after the fix, including the new Unicode regression coverage.
Scope notes