Skip to content

fix(echo,text-tools,xxd,*sum): octal \0nnn, CRLF CR retention, xxd -p wrap + text marker (#1203 #1204 #1205) - #1224

Merged
caomengxuan666 merged 3 commits into
mainfrom
fix/1203-1204-1205-echo-cr-xxd
Oct 17, 2026
Merged

caomengxuan666 merged 3 commits into
mainfrom
fix/1203-1204-1205-echo-cr-xxd

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

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/bin coreutils 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 (commit fe63573)

process_escapes read up to three octal digits starting at the leading
zero, so \0 was treated as a control byte and the rest as text.

invocation GNU 8.32 / 9.4 before (echo.exe) after
echo -e '\0101' 41 0a 08 31 0a 41 0a
echo -e '\0777' ff 0a 3f 37 0a ff 0a

The issue's second case, echo -e '\101', is only a divergence from bash's
builtin
, which the issue used as "GNU": both GNU coreutils echo 8.32 and
9.4 read the old-style \nnn form, so \101 is 41 0a on both and already
matched. 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, \0a were already
correct and stay correct.

#1204 — trailing CR from CRLF input (commit 5eecdf1)

grep, cut, fold, expand, nl and paste deleted a trailing \r, on
the operand and the stdin path. GNU never strips it.

case (printf 'a\r\n' input) GNU before after
grep -a 'a$' f rc=1, no output 61 0a 72 63 3d 30 (a, rc=0) rc=1, no output
cut -c1- f 61 0d 0a 61 0a 61 0d 0a
fold -w10 f 61 0d 0a 61 0a 61 0d 0a
expand -t4 f 61 0d 0a 61 0a 61 0d 0a
nl f 2020202020310961 0d0a ...61 0a ...61 0d 0a
paste f 61 0d 0a 61 0a 61 0d 0a

The stdin form now agrees with the operand form, keeping the #1212 invariant.
grep -U/--binary no longer affects the CR (GNU's -U only disables Windows
text 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 -p wrap + checksum marker (commit a8b76fc)

  • xxd -p wrapped at 32 hex chars/line; GNU uses 60 (30 bytes). Default the
    plain dump to 30 columns when -c is absent; explicit -c still wins.
    Verified identical output for -p, -p -c 8/16/30, -p -u, -p -l 70,
    -p -s 3 against the Windows xxd.

  • md5sum/sha1sum/sha224sum/sha256sum/sha384sum/sha512sum/b2sum
    printed hash *name (binary marker) by default on Windows. GNU's default is
    the text marker hash name; -b/--binary selects *, and the last of
    -b/-t wins (including --tag's explicit---text rejection). The bytes
    hashed were already raw and stay raw.

    Consumer-visible change: default output now has two spaces instead of
    *. sum -c accepts both markers, and -b restores the old marker.

Note: option help text is i18n-keyed, so grep -U's stale description
("do not strip CR at EOL") was left unchanged to avoid a cross-repo catalog
update; only the accurate source comment was updated.

Tests

ctest --test-dir build-vs -R "^(echo|grep|egrep|fgrep|cut|fold|expand|nl|paste|xxd|md5sum|sha1sum|sha224sum|sha256sum|sha384sum|sha512sum|b2sum)\."

  • before: 422/422 passed
  • after: 430/430 passed (9 new *_issue12NN tests, 1 obsolete
    paste_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 *sum NUL-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).

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
caomengxuan666 force-pushed the fix/1203-1204-1205-echo-cr-xxd branch from a8b76fc to 393e385 Compare October 17, 2026 08:08
@caomengxuan666
caomengxuan666 merged commit 3c42903 into main Oct 17, 2026
5 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/1203-1204-1205-echo-cr-xxd branch October 21, 2026 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant