* src/ls.c (decode_switches): Flag ',' for quoting when needed.
* tests/ls/m-option.sh: Add a test case.
* NEWS: Mention the improvement.
---
NEWS | 3 +++
src/ls.c | 6 ++++++
tests/ls/m-option.sh | 8 ++++++++
3 files changed, 17 insertions(+)
diff --git a/NEWS b/NEWS
index b1ec92562..39967eab1 100644
--- a/NEWS
+++ b/NEWS
@@ -60,6 +60,9 @@ GNU coreutils NEWS -*-
outline -*-
'df', 'du', 'ls', 'od', 'pr', and 'sort' now escape invalid arguments in
error
messages for options expecting an integer.
+ 'ls -m' now quotes files names containing commas when appropriate,
+ so users can 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 3d583b85f..d54ef3d98 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 c9502e915..9b3302dd8 100755
--- a/tests/ls/m-option.sh
+++ b/tests/ls/m-option.sh
@@ -50,4 +50,12 @@ 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
+touch 'com, ma' || framework_failure_
+printf '%s\n' "'com, ma'" > exp || framework_failure_
+for qs in shell shell-escape; do
+ ls -m --quoting-style="$qs" 'com, ma' > out || fail=1
+ compare exp out || fail=1
+done
+
Exit $fail
--
2.55.0