]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: stat: cover %N escaping of control characters
authorSylvestre Ledru <sylvestre@debian.org>
Fri, 29 May 2026 16:55:48 +0000 (18:55 +0200)
committerPádraig Brady <P@draigBrady.com>
Fri, 29 May 2026 18:19:36 +0000 (19:19 +0100)
The default shell-escape quoting style escapes control characters in
file names (e.g. newlines) as $'...' sequences, but no test exercised
this; only the single-quote character was covered.
referenced here: https://github.com/uutils/coreutils/issues/9925

* tests/stat/stat-fmt.sh: Add a case with a file name containing
contiguous and separated newlines.
https://github.com/coreutils/coreutils/pull/271

tests/stat/stat-fmt.sh

index dec5f98dbf04de8e3020da3ff82163ad68b77d14..11cc09bc93da9e69e1506b7961fe2b7ca2022f02 100755 (executable)
@@ -40,6 +40,19 @@ cat <<\EOF >exp
 EOF
 compare exp out || fail=1
 
+# ensure control characters in file names are escaped by %N
+# using the default shell-escape quoting style.
+nl='
+'
+fname="a${nl}${nl}b${nl}c"
+touch "$fname" || framework_failure_
+stat -c%N "$fname" > out || fail=1
+# contiguous control characters are clumped into one $'...' escape.
+cat <<\EOF >exp
+'a'$'\n\n''b'$'\n''c'
+EOF
+compare exp out || fail=1
+
 # Check the behavior with invalid values of QUOTING_STYLE.
 for style in '' 'abcdef'; do
   QUOTING_STYLE="$style" stat -c%%%N \' > out 2> err || fail=1