Repository navigation
fix(echo,text-tools,xxd,*sum): octal \0nnn, CRLF CR retention, xxd -p wrap + text marker (#1203 #1204 #1205) - #1224
Merged
Conversation
echo -e mis-parsed the \0nnn form in both directions: it read up to three octal digits starting at the leading zero, so \0101 became \010 followed by a literal '1' (0x08 0x31) and \0777 became '?7'. GNU coreutils echo treats the leading zero as a prefix and reads up to three further octal digits, so \0101 is octal 101 = 'A' and \0777 is 0xFF. Split case '0' from the old-style case '1'..'7' (which is unchanged) and advance past the prefix. The issue's second case, \101, is only a divergence from bash's builtin: GNU coreutils echo 8.32 and 9.4 both read the old-style \nnn form, so \101 stays 'A' and the behaviour is pinned by a test.
grep, cut, fold, expand, nl and paste deleted a trailing '\r' from every line, on the file-operand and the stdin paths alike. GNU never strips it: the CR is data, so 'a$' does not match a CRLF line, whole-line (-x) fails, and a selected field that ends in CR prints it. The project's own coreutils-9.7 audit lists this as the largest differential-failure class. Remove the stripping so the tools are byte-exact with GNU on both the operand and the pipe/redirect form (#1212 keeps stdin == operand). grep's -U/--binary becomes a no-op (GNU's -U only disables Windows text translation, which WinuxCmd never performs); the option is still accepted. The -z/NUL record paths are untouched. Adjacent tools with the same CR-strip behaviour were left alone: unexpand, fmt, sort, comm, join, column, pr, look, du, cpio.
xxd -p wrapped at 32 hex characters (16 bytes) per line; GNU wraps at 60 (30 bytes). Default the plain dump to 30 columns when -c is not given; an explicit -c still wins, and the normal/include formats keep 16/12. md5sum, sha1sum, sha224sum, sha256sum, sha384sum, sha512sum and b2sum printed 'hash *name' by default because Windows defaulted to binary mode. GNU's default is the text marker 'hash name'; -b/--binary selects '*', and the last of -b/-t wins. Only the marker changes -- the bytes hashed were already raw and stay raw. Consumers that read the default output will now see two spaces instead of ' *'; -c accepts both, and scripts that want the old marker can pass -b.
caomengxuan666
force-pushed
the
fix/1203-1204-1205-echo-cr-xxd
branch
from
October 17, 2026 08:08
a8b76fc to
393e385
Compare
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 #1203, fixes #1204, fixes #1205.
Three independent output/byte divergences from GNU, each verified byte-for-byte
against the GNU oracles (
D:/Git/usr/bincoreutils 8.32 and WSL coreutils 9.4,plus the Windows
xxd). One commit per issue; the touched files do not overlap.#1203 —
echo -e\0nnn(commitfe63573)process_escapesread up to three octal digits starting at the leadingzero, so
\0was treated as a control byte and the rest as text.echo -e '\0101'41 0a08 31 0a41 0aecho -e '\0777'ff 0a3f 37 0aff 0aThe issue's second case,
echo -e '\101', is only a divergence from bash'sbuiltin, which the issue used as "GNU": both GNU coreutils
echo8.32 and9.4 read the old-style
\nnnform, so\101is41 0aon both and alreadymatched. That behaviour is pinned by a test rather than changed; changing it
would break coreutils parity and the existing
echo_old_style_octal_*tests.\0,\08,\43foo,\1011,\012,\0000,\400,\0awere alreadycorrect and stay correct.
#1204 — trailing CR from CRLF input (commit
5eecdf1)grep,cut,fold,expand,nlandpastedeleted a trailing\r, onthe operand and the stdin path. GNU never strips it.
printf 'a\r\n'input)grep -a 'a$' f61 0a 72 63 3d 30(a, rc=0)cut -c1- f61 0d 0a61 0a61 0d 0afold -w10 f61 0d 0a61 0a61 0d 0aexpand -t4 f61 0d 0a61 0a61 0d 0anl f2020202020310961 0d0a...61 0a...61 0d 0apaste f61 0d 0a61 0a61 0d 0aThe stdin form now agrees with the operand form, keeping the #1212 invariant.
grep -U/--binaryno longer affects the CR (GNU's-Uonly disables Windowstext translation, which WinuxCmd never does); the option is still accepted.
The
-z/NUL record paths were not touched.Same-class tools found but left alone (out of scope, still strip CR):
unexpand,fmt,sort,comm,join,column,pr,look,du,cpio.#1205 —
xxd -pwrap + checksum marker (commita8b76fc)xxd -pwrapped at 32 hex chars/line; GNU uses 60 (30 bytes). Default theplain dump to 30 columns when
-cis absent; explicit-cstill wins.Verified identical output for
-p,-p -c 8/16/30,-p -u,-p -l 70,-p -s 3against the Windowsxxd.md5sum/sha1sum/sha224sum/sha256sum/sha384sum/sha512sum/b2sumprinted
hash *name(binary marker) by default on Windows. GNU's default isthe text marker
hash name;-b/--binaryselects*, and the last of-b/-twins (including--tag's explicit---textrejection). The byteshashed were already raw and stay raw.
Consumer-visible change: default output now has two spaces instead of
*.sum -caccepts both markers, and-brestores the old marker.Tests
ctest --test-dir build-vs -R "^(echo|grep|egrep|fgrep|cut|fold|expand|nl|paste|xxd|md5sum|sha1sum|sha224sum|sha256sum|sha384sum|sha512sum|b2sum)\."*_issue12NNtests, 1 obsoletepaste_newline_mode_trims_trailing_cr…replaced)Existing tests that asserted the old behaviour were updated to byte-exact GNU
expectations (grep anchoring, the six CR tests, the
*sumNUL-marker tests).Scripted byte comparison of stdout/stderr/rc against the GNU oracles: 84/84
behavioural matches; the only raw differences are the operand path spelling
(
C:\…in WinuxCmd vs/mnt/c/…in WSL).