Skip to content

Commit 1c70eaa

Browse files
authored
Edit solution of #116555
1 parent 598b5eb commit 1c70eaa

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/uu/numfmt/src/numfmt.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,16 @@ fn format_and_write<W: std::io::Write>(
4848
};
4949

5050
// Return false if the input is in scientific notation
51-
if line.contains(&101) && line[line.len() - 1] != 69 && line.contains(&69) && line[line.len() - 1] != 101 && line[0] >= 48 && line[0] <= 57 {
52-
let err = NumfmtError::FormattingError(String::from_utf8_lossy(line).to_string());
53-
let _ = writeln!(stderr(), "numfmt: invalid number: '{err}'");
54-
55-
return Ok(false);
51+
if let Some(pos) = line.iter().position(|&b| b == b'E' || b == b'e') {
52+
if pos < line.len() - 1 {
53+
if line[pos + 1] >= 48 && line[pos + 1] <= 57 {
54+
let errormsg = format!(
55+
"invalid suffix in input: '{}'",
56+
NumfmtError::FormattingError(String::from_utf8_lossy(line).to_string())
57+
);
58+
return Err(Box::new(NumfmtError::FormattingError(errormsg)));
59+
}
60+
}
5661
}
5762

5863
// In non-abort modes we buffer the formatted output so that on error we

0 commit comments

Comments
 (0)