mirror of
https://github.com/uutils/coreutils
synced 2024-12-14 07:12:44 +00:00
head: interpret size as decimal
This commit is contained in:
parent
a8219403a6
commit
f10faf21bc
2 changed files with 16 additions and 1 deletions
|
@ -114,7 +114,13 @@ pub fn parse_num(src: &str) -> Result<(u64, bool), ParseSizeError> {
|
|||
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)]
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
#[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]
|
||||
fn test_multiple_nonexistent_files() {
|
||||
|
|
Loading…
Reference in a new issue