numfmt: fix panic on multibyte locale decimal separator - #14167
Open
MadeNavaneeth wants to merge 1 commit into
Open
numfmt: fix panic on multibyte locale decimal separator#14167MadeNavaneeth wants to merge 1 commit into
MadeNavaneeth wants to merge 1 commit into
Conversation
|
GNU testsuite comparison: |
`find_valid_number_with_suffix` used `numeric_part.len()` (byte count) as a char count in `chars().skip()`, causing desync when the numeric part contains multibyte characters (e.g. Arabic `٫` separator). This led to slicing into a multibyte char boundary and panicking. Fixed by using `chars().count()` for char iteration and computing byte indices via `char_indices().nth()` for string slicing. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
MadeNavaneeth
force-pushed
the
fix/numfmt-multibyte-panic
branch
from
August 27, 2026 04:15
59a618a to
057d56a
Compare
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.
Fixes #13937
What
numfmtpanics withbyte index N is not a char boundarywhen the input contains a multibyte locale decimal separator (e.g. Arabic٫U+066B inar_SA.UTF-8) before a multibyte character and a suffix.Root cause
find_valid_number_with_suffixusednumeric_part.len()(byte length) as a char count inchars().skip(). When the numeric part contains multibyte characters, the byte count exceeds the char count, causing the char iterator to overshoot and the byte-slice index to land mid-character.Fix
numeric_part.chars().count()for thechars().skip()callchar_indices().nth()for string slicingTesting
cargo clippy -p uu_numfmt -- -D warningscleanLC_ALL=ar_SA.UTF-8 numfmt --from=si '1٫€K'now exits with error 2 instead of panicking🤖 Generated with Codebuff
Co-Authored-By: Codebuff noreply@codebuff.com