head: interpret size as decimal

This commit is contained in:
John Shin 2023-05-30 11:26:39 -07:00
parent a8219403a6
commit f10faf21bc
2 changed files with 16 additions and 1 deletions

View file

@ -114,7 +114,13 @@ pub fn parse_num(src: &str) -> Result<(u64, bool), ParseSizeError> {
return Err(ParseSizeError::ParseFailure(src.to_string())); return Err(ParseSizeError::ParseFailure(src.to_string()));
} }
parse_size(size_string).map(|n| (n, all_but_last)) // remove leading zeros so that size is interpreted as decimal, not octal
let trimmed_string = size_string.trim_start_matches('0');
if trimmed_string.is_empty() {
Ok((0, all_but_last))
} else {
parse_size(trimmed_string).map(|n| (n, all_but_last))
}
} }
#[cfg(test)] #[cfg(test)]

View file

@ -189,6 +189,15 @@ fn test_no_such_file_or_directory() {
.stderr_contains("cannot open 'no_such_file.toml' for reading: No such file or directory"); .stderr_contains("cannot open 'no_such_file.toml' for reading: No such file or directory");
} }
#[test]
fn test_lines_leading_zeros() {
new_ucmd!()
.arg("--lines=010")
.pipe_in("\n\n\n\n\n\n\n\n\n\n\n\n")
.succeeds()
.stdout_is("\n\n\n\n\n\n\n\n\n\n");
}
/// Test that each non-existent files gets its own error message printed. /// Test that each non-existent files gets its own error message printed.
#[test] #[test]
fn test_multiple_nonexistent_files() { fn test_multiple_nonexistent_files() {