Skip to content

Commit e3a4b05

Browse files
fix: validate if thousands_separator is not multi byte
1 parent 49048b4 commit e3a4b05

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/uu/sort/src/numeric_str_cmp.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct NumInfo {
2828
#[derive(Debug, PartialEq, Eq, Clone)]
2929
pub struct NumInfoParseSettings {
3030
pub accept_si_units: bool,
31-
pub thousands_separator: Option<char>,
31+
pub thousands_separator: Option<u8>,
3232
pub decimal_pt: Option<u8>,
3333
}
3434

@@ -74,7 +74,7 @@ impl NumInfo {
7474

7575
if matches!(
7676
parse_settings.thousands_separator,
77-
Some(c) if c == char as char
77+
Some(c) if c == char
7878
) {
7979
continue;
8080
}
@@ -306,7 +306,7 @@ mod tests {
306306
NumInfo::parse(
307307
n,
308308
&NumInfoParseSettings {
309-
thousands_separator: Some(','),
309+
thousands_separator: Some(b','),
310310
..Default::default()
311311
}
312312
),

src/uu/sort/src/sort.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,9 +1087,14 @@ impl FieldSelector {
10871087
let mut range_str = &line[self.get_range(line, tokens)];
10881088
if self.settings.mode == SortMode::Numeric || self.settings.mode == SortMode::HumanNumeric {
10891089
// Get the thousands separator from the locale, handling cases where the separator is empty or multi-character
1090-
let thousands_separator = i18n::decimal::locale_grouping_separator()
1091-
.parse::<char>()
1092-
.ok();
1090+
let locale_thousands_separator = i18n::decimal::locale_grouping_separator().as_bytes();
1091+
1092+
// Upstream GNU coreutils ignore multibyte thousands separators
1093+
// (FIXME in C source). We keep the same single-byte behavior.
1094+
let thousands_separator = match locale_thousands_separator {
1095+
[b] => Some(*b),
1096+
_ => None,
1097+
};
10931098

10941099
// Parse NumInfo for this number.
10951100
let (info, num_range) = NumInfo::parse(

0 commit comments

Comments
 (0)