mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
Merge pull request #6674 from andrewliebenow/od-allow-trailing-characters-in-address-radix
od: allow trailing characters in address radix
This commit is contained in:
commit
dfe3e38063
2 changed files with 31 additions and 22 deletions
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
// spell-checker:ignore (clap) dont
|
// spell-checker:ignore (clap) dont
|
||||||
// spell-checker:ignore (ToDO) formatteriteminfo inputdecoder inputoffset mockstream nrofbytes partialreader odfunc multifile exitcode
|
// spell-checker:ignore (ToDO) formatteriteminfo inputdecoder inputoffset mockstream nrofbytes partialreader odfunc multifile exitcode
|
||||||
|
// spell-checker:ignore Anone
|
||||||
|
|
||||||
mod byteorder_io;
|
mod byteorder_io;
|
||||||
mod formatteriteminfo;
|
mod formatteriteminfo;
|
||||||
|
@ -169,12 +170,13 @@ impl OdOptions {
|
||||||
let radix = match matches.get_one::<String>(options::ADDRESS_RADIX) {
|
let radix = match matches.get_one::<String>(options::ADDRESS_RADIX) {
|
||||||
None => Radix::Octal,
|
None => Radix::Octal,
|
||||||
Some(s) => {
|
Some(s) => {
|
||||||
|
// Other implementations of od only check the first character of this argument's value.
|
||||||
|
// This means executing "od -Anone" is equivalent to "od -An".
|
||||||
|
// Existing users of od rely on this behavior:
|
||||||
|
// https://github.com/landley/toybox/blob/d50372cad35d5dd12e6391c3c7c901a96122dc67/scripts/make.sh#L239
|
||||||
|
// https://github.com/google/jsonnet/blob/913281d203578bb394995bacc792f2576371e06c/Makefile#L212
|
||||||
let st = s.as_bytes();
|
let st = s.as_bytes();
|
||||||
if st.len() == 1 {
|
let radix: char = *(st.first().expect("should be caught by clap")) as char;
|
||||||
let radix: char = *(st
|
|
||||||
.first()
|
|
||||||
.expect("byte string of length 1 lacks a 0th elem"))
|
|
||||||
as char;
|
|
||||||
match radix {
|
match radix {
|
||||||
'd' => Radix::Decimal,
|
'd' => Radix::Decimal,
|
||||||
'x' => Radix::Hexadecimal,
|
'x' => Radix::Hexadecimal,
|
||||||
|
@ -187,12 +189,6 @@ impl OdOptions {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return Err(USimpleError::new(
|
|
||||||
1,
|
|
||||||
"Radix must be one of [d, o, n, x]".to_string(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
// For the full copyright and license information, please view the LICENSE
|
// For the full copyright and license information, please view the LICENSE
|
||||||
// file that was distributed with this source code.
|
// file that was distributed with this source code.
|
||||||
|
|
||||||
// spell-checker:ignore abcdefghijklmnopqrstuvwxyz
|
// spell-checker:ignore abcdefghijklmnopqrstuvwxyz Anone
|
||||||
|
|
||||||
use crate::common::util::TestScenario;
|
use crate::common::util::TestScenario;
|
||||||
use unindent::unindent;
|
use unindent::unindent;
|
||||||
|
@ -579,6 +579,19 @@ fn test_invalid_offset() {
|
||||||
new_ucmd!().arg("-Ab").fails();
|
new_ucmd!().arg("-Ab").fails();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_offset_compatibility() {
|
||||||
|
let input = [0u8; 4];
|
||||||
|
let expected_output = " 000000 000000\n";
|
||||||
|
|
||||||
|
new_ucmd!()
|
||||||
|
.arg("-Anone")
|
||||||
|
.run_piped_stdin(input)
|
||||||
|
.no_stderr()
|
||||||
|
.success()
|
||||||
|
.stdout_is(expected_output);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_skip_bytes() {
|
fn test_skip_bytes() {
|
||||||
let input = "abcdefghijklmnopq";
|
let input = "abcdefghijklmnopq";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue