From: Sylvestre Ledru Date: Sun, 26 Jul 2026 14:59:29 +0000 (+0200) Subject: tests: ls: cover quoting in the C.UTF-8 locale X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=fc426cc1421eed663f5573a4709a4de4cd562c17;p=thirdparty%2Fcoreutils.git tests: ls: cover quoting in the C.UTF-8 locale 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 --- diff --git a/tests/ls/quoting-utf8.sh b/tests/ls/quoting-utf8.sh index 8b15c38f52..3151b3cb16 100755 --- a/tests/ls/quoting-utf8.sh +++ b/tests/ls/quoting-utf8.sh @@ -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