Skip to content
Merged
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
13 changes: 13 additions & 0 deletions src/uu/numfmt/src/numfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ fn format_and_write<W: std::io::Write>(
None => input_line,
};

// Return false if the input is in scientific notation
if let Some(pos) = line.iter().position(|&b| b == b'E' || b == b'e') {
if pos < line.len() - 1 {
if line[pos + 1].is_ascii_digit() {
let err = format!(
"invalid suffix in input: '{}'",
String::from_utf8_lossy(line)
);
return Err(Box::new(NumfmtError::FormattingError(err)));
}
}
}

// In non-abort modes we buffer the formatted output so that on error we
// can emit the original line instead.
let buffer_output = !matches!(options.invalid, InvalidModes::Abort);
Expand Down
1 change: 0 additions & 1 deletion tests/by-util/test_numfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,6 @@ fn test_large_integer_precision_loss_issue_11654() {
// uutils accepts scientific notation (`1e9`, `5e-3`, ...); GNU rejects it
// as "invalid suffix in input".
#[test]
#[ignore = "GNU compat: see uutils/coreutils#11655"]
fn test_scientific_notation_rejected_by_gnu_issue_11655() {
new_ucmd!()
.arg("1e9")
Expand Down
Loading