]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: ls: cover quoting in the C.UTF-8 locale
authorSylvestre Ledru <sylvestre@debian.org>
Sun, 26 Jul 2026 14:59:29 +0000 (16:59 +0200)
committerPádraig Brady <P@draigBrady.com>
Mon, 27 Jul 2026 12:52:51 +0000 (13:52 +0100)
The quoting characters and the printability of a multibyte character are
selected by the locale's codeset, not by its language, but no test
covered a locale that has a UTF-8 codeset and no language.

* tests/ls/quoting-utf8.sh: Check that in C.UTF-8 the locale/clocale
styles use the Unicode quotes and that literal/escape/shell-escape pass
a multibyte character through unaltered, whereas the plain C locale
octal-escapes it or replaces it with '?'.

Link: https://github.com/coreutils/coreutils/pull/323
tests/ls/quoting-utf8.sh

index 8b15c38f521f1aaa495c7bda6dec7ed7d5711a0d..3151b3cb161b9fc9c59ff372d393b7fa937abd35 100755 (executable)
@@ -75,4 +75,37 @@ LC_ALL=C ls --quoting-style=clocale > out_clocale_c || fail=1
 grep '^"hello world"$' out_clocale_c > /dev/null 2>&1 \
   || { echo "clocale C: expected ASCII double quotes"; fail=1; }
 
+# C.UTF-8 provides no translations either, but its codeset is UTF-8.
+# It is the codeset, not the language, that selects the quoting characters
+# and decides whether a multibyte character is printable.
+if test "$(LC_ALL=C.UTF-8 locale charmap 2>/dev/null)" = UTF-8; then
+  # U+00EF = \xc3\xaf (LATIN SMALL LETTER I WITH DIAERESIS)
+  mb=$(printf 'na\303\257ve')
+  touch "$mb" || framework_failure_
+
+  for style in locale clocale; do
+    LC_ALL=C.UTF-8 ls --quoting-style=$style "$mb" > out_cutf8 || fail=1
+    printf '%s%s%s\n' "$lq" "$mb" "$rq" > exp_cutf8 || framework_failure_
+    compare exp_cutf8 out_cutf8 || fail=1
+  done
+
+  # The character is printable here, so it is passed through unaltered.
+  printf '%s\n' "$mb" > exp_cutf8 || framework_failure_
+  for style in literal escape shell-escape; do
+    LC_ALL=C.UTF-8 ls --hide-control-chars --quoting-style=$style "$mb" \
+      > out_cutf8 || fail=1
+    compare exp_cutf8 out_cutf8 || fail=1
+  done
+
+  # Whereas in the C locale the same bytes are not printable.
+  LC_ALL=C ls --quoting-style=escape "$mb" > out_c || fail=1
+  printf 'na\\303\\257ve\n' > exp_c || framework_failure_
+  compare exp_c out_c || fail=1
+
+  LC_ALL=C ls --hide-control-chars --quoting-style=literal "$mb" > out_c \
+    || fail=1
+  printf 'na??ve\n' > exp_c || framework_failure_
+  compare exp_c out_c || fail=1
+fi
+
 Exit $fail