mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Correctly parse numbers starting with 0 as octal
This commit is contained in:
parent
c513692bae
commit
fd1e0e6dd7
2 changed files with 21 additions and 11 deletions
|
@ -569,16 +569,20 @@ impl Config {
|
||||||
};
|
};
|
||||||
|
|
||||||
let width = match options.value_of(options::WIDTH) {
|
let width = match options.value_of(options::WIDTH) {
|
||||||
Some(x) => match x.parse::<u16>() {
|
Some(x) => {
|
||||||
Ok(u) => {
|
if x.starts_with('0') && x.len() > 1 {
|
||||||
if u != 0 && x.starts_with('0') {
|
// Read number as octal
|
||||||
return Err(LsError::InvalidLineWidth(x.into()).into());
|
match u16::from_str_radix(x, 8) {
|
||||||
} else {
|
Ok(v) => v,
|
||||||
u
|
Err(_) => return Err(LsError::InvalidLineWidth(x.into()).into()),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
match x.parse::<u16>() {
|
||||||
|
Ok(u) => u,
|
||||||
|
Err(_) => return Err(LsError::InvalidLineWidth(x.into()).into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_) => return Err(LsError::InvalidLineWidth(x.into()).into()),
|
}
|
||||||
},
|
|
||||||
None => match termsize::get() {
|
None => match termsize::get() {
|
||||||
Some(size) => size.cols,
|
Some(size) => size.cols,
|
||||||
None => match std::env::var_os("COLUMNS") {
|
None => match std::env::var_os("COLUMNS") {
|
||||||
|
|
|
@ -650,13 +650,19 @@ fn test_ls_width() {
|
||||||
.stdout_only("test-width-1 test-width-2 test-width-3 test-width-4\n");
|
.stdout_only("test-width-1 test-width-2 test-width-3 test-width-4\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
for option in ["-w 06", "-w=06", "--width=06", "--width 06", "--wid=06"] {
|
for option in [
|
||||||
|
"-w 062",
|
||||||
|
"-w=062",
|
||||||
|
"--width=062",
|
||||||
|
"--width 062",
|
||||||
|
"--wid=062",
|
||||||
|
] {
|
||||||
scene
|
scene
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.args(&option.split(' ').collect::<Vec<_>>())
|
.args(&option.split(' ').collect::<Vec<_>>())
|
||||||
.arg("-C")
|
.arg("-C")
|
||||||
.fails()
|
.succeeds()
|
||||||
.stderr_contains("invalid line width");
|
.stdout_only("test-width-1 test-width-3\ntest-width-2 test-width-4\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
scene
|
scene
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue