dd: quote the operand value in an error, as GNU does - #14294
Open
arbelonson-source wants to merge 1 commit into
Open
dd: quote the operand value in an error, as GNU does#14294arbelonson-source wants to merge 1 commit into
arbelonson-source wants to merge 1 commit into
Conversation
`dd` puts the value it rejected into the message unquoted, so a byte the
terminal will not show is sent to the terminal as itself:
$ dd status=$'\1'
dd: invalid status level: <the byte>
GNU spells it out instead, and quotes the value even when it is ordinary:
$ dd status=$'\1'
dd: invalid status level: '\001'
$ dd status=bogus
dd: invalid status level: 'bogus'
GNU uses two quoting styles here, and which one goes where is visible from
the outside. The choices -- `status=`, `iflag=`, `oflag=`, `conv=` -- take
plain quoting, where an escape stays inside the quotes:
dd: invalid status level: 'a\'b'
while numbers and operand names take shell syntax, where an unprintable
byte ends the quoted run and a quote in the value switches which quotes
are used:
dd: invalid number: ''$'\001'
dd: invalid number: "a'b"
dd: unrecognized operand ''$'\001''=1'
Both are already in `uucore::quoting_style`, so this is a matter of asking
for them. The quotes move out of the message and into the quoting, which
is what supplies them for every value now.
Fixes uutils#13868.
|
GNU testsuite comparison: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #13868.
ddputs the value it rejected straight into the message, so a byte the terminal will not show is sent to the terminal as itself. GNU spells it out, and quotes the value even when it is ordinary:Two styles, and which goes where
GNU uses two quoting styles in
dd, and which one applies to which message is visible from the outside. The choices —status=,iflag=,oflag=,conv=— take plain quoting, where an escape stays inside the quotes:while numbers and operand names take shell syntax, where an unprintable byte ends the quoted run rather than being escaped inside it, and a quote in the value switches which quotes are used:
Both styles already exist in
uucore::quoting_style(C { quotes: Single }andSHELL_ESCAPE_QUOTE) and both already match GNU byte for byte —ls --quoting-style=localeand--quoting-style=shell-escape-alwaysagree with GNU on all of these today. So this is a matter of asking for them.The quotes move out of the Fluent messages and into the quoting, since that is what supplies them now;
fr-FR.ftlgets the same mechanical change, and its rendered output is unchanged for ordinary values.Not covered
Two differences turned up next to this one that are unrelated to quoting and unchanged by this PR — happy to file them if they are not already known:
dd skip=8E ibs=8reportsinvalid number: '18446744073709551615', the clamped internal value, where GNU echoes the operand as typed ('8E'). GNU also acceptsskip=9223372036854775807and fails later at skip time, where we reject it during parsing.dd bs=0xwarns'0x' is a zero multiplierand continues; GNU errors withinvalid number: '0x'.Testing
LC_ALL=C, over every value-carrying operand (status,iflag,oflag,conv,bs,ibs,obs,cbs,count,skip,seek) crossed with unprintable bytes, tab, newline, DEL, backslash, single and double quote, space, empty, non-ASCII, and shell metacharacters, plus unrecognized operands: 174 match, and the 3 that do not are the two pre-existing differences listed above, verified identical onmain.test_operand_value_is_quoted_like_gnuintest_dd.rs, covering both styles.cargo test --features dd --test tests -- test_dd: 145 passed, 0 failed (144 pre-existing, 1 new);cargo test -p uu_dd: 93 passed.moz-fluent-lint --config .github/fluent_linter_config.yml src/uu/dd/locales: no errors.cargo fmt --checkandcargo clippy -p uu_dd --all-targets: clean.Disclosure
Prepared with AI assistance (Claude Opus 5, via Claude Code), per the AI policy in CONTRIBUTING.md. GNU's behaviour was established by running the installed GNU binary as a black box; I did not read GNU coreutils source. All testing was run locally.