From: Pádraig Brady
Date: Thu, 9 Jul 2026 17:15:15 +0000 (+0100) Subject: ls: with -m, quote names containing commas when appropriate X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=04590790d46b4349a996bbd6ca2698a644660787;p=thirdparty%2Fcoreutils.git ls: with -m, quote names containing commas when appropriate * src/ls.c (decode_switches): Flag ',' for quoting when needed. * tests/ls/m-option.sh: Add a test case. * NEWS: Mention the improvement. --- diff --git a/NEWS b/NEWS index 28d1da64d9..523f0047c0 100644 --- a/NEWS +++ b/NEWS @@ -84,6 +84,9 @@ GNU coreutils NEWS -*- outline -*- 'install -C' will now avoid updating file metadata when the destination already has the appropriate ownership and permissions. + 'ls -m' now quotes files names containing commas when appropriate, + so users can better distinguish separating commas. + 'sort' will now better use available memory and parallel operation when reading from unknown sized inputs like pipes. diff --git a/src/ls.c b/src/ls.c index 0b4695a333..b2335b2179 100644 --- a/src/ls.c +++ b/src/ls.c @@ -2359,6 +2359,12 @@ decode_switches (int argc, char **argv) for (char const *p = &"*=>@|"[indicator_style - file_type]; *p; p++) set_char_quoting (filename_quoting_options, *p, 1); } + if (format == with_commas + && (qs == shell_quoting_style + || qs == shell_escape_quoting_style + || qs == c_maybe_quoting_style + || qs == escape_quoting_style)) + set_char_quoting (filename_quoting_options, ',', 1); dirname_quoting_options = clone_quoting_options (NULL); set_char_quoting (dirname_quoting_options, ':', 1); diff --git a/tests/ls/m-option.sh b/tests/ls/m-option.sh index c9502e9156..afe3fd4156 100755 --- a/tests/ls/m-option.sh +++ b/tests/ls/m-option.sh @@ -50,4 +50,26 @@ printf '%s\n' 'a, bb' > exp || framework_failure_ ls -w5 -m a bb > out || fail=1 compare exp out || fail=1 +# Ensure commas in names are quoted appropriately for all quoting styles. +# Without this quoting, interactive output could become confusing, +# especially in the presence of NBSP etc. +touch 'com,ma' || framework_failure_ +cat <<\EOF > exp || framework_failure_ +literal: com,ma +shell: 'com,ma' +shell-always: 'com,ma' +shell-escape: 'com,ma' +shell-escape-always: 'com,ma' +c: "com,ma" +c-maybe: "com,ma" +escape: com\,ma +locale: 'com,ma' +clocale: "com,ma" +EOF +for qs in $(cut -d: -f1 exp); do + printf '%s: ' "$qs" + ls -m --quoting-style="$qs" 'com,ma' || fail=1 +done > out +compare exp out || fail=1 + Exit $fail