Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/uu/numfmt/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn find_valid_number_with_suffix(s: &str, unit: Unit) -> Option<&str> {
let accepts_suffix = unit != Unit::None;
let accepts_i = [Unit::Auto, Unit::Iec(true)].contains(&unit);

let mut characters = s.chars().skip(numeric_part.len());
let mut characters = s[numeric_part.len()..].chars();
let potential_suffix = characters.next();
let potential_i = characters.next();

Expand Down
23 changes: 23 additions & 0 deletions tests/by-util/test_numfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use rstest::rstest;
use uutests::new_ucmd;
use uutests::util::is_locale_available;

#[test]
fn test_invalid_arg() {
Expand Down Expand Up @@ -493,6 +494,28 @@ fn test_first_blank_between_fields_is_written_as_space_issue15552() {
.stderr_is("numfmt: invalid number: 'a'\n");
}

#[uutests::wasi_ignore(NoLocaleData)]
#[test]
fn test_from_multibyte_decimal_separator_invalid_suffix() {
// fa_IR's decimal separator `٫` is multibyte, so a byte length used as a
// char count made the suffix lookup slice inside the `€` and panic.
let locale = "fa_IR.UTF-8";
Comment on lines +500 to +502
if !is_locale_available(locale) {
return;
}
new_ucmd!()
.env("LC_ALL", locale)
.args(&["--from=si", "1٫€K"])
.fails_with_code(2)
.stderr_only("numfmt: invalid suffix in input '1٫€K': '€K'\n");

new_ucmd!()
.env("LC_ALL", locale)
.args(&["--from=auto", "1٫€Ki"])
.fails_with_code(2)
.stderr_only("numfmt: invalid suffix in input '1٫€Ki': '€Ki'\n");
}

#[test]
fn test_format_selected_fields() {
new_ucmd!()
Expand Down
Loading