On 10/07/2026 04:00, Collin Funk wrote:
Pádraig Brady <[email protected]> writes:
* 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.
+
Can't you just split by ", " with the output before this patch? E.g.,
looking at the following:
$ mkdir a; (cd a && touch f1 f1, f1,f2 f1,f2, 'f1, f2' 'f1, f2,')
$ ls -m a
f1, f1,, f1,f2, f1,f2,, 'f1, f2', 'f1, f2,'
We know the comma is a part of the file name if it is not followed by a
space. And it does have a ", " in it's name it will be quoted anyways
because of the space. Am I missing something?
Also, posting the output with your patch for others reference:
$ ./src/ls -m a
f1, 'f1,', 'f1,f2', 'f1,f2,', 'f1, f2', 'f1, f2,'
You'd still need to care for filenames with ", " in their name in this
case.
Yes good point.
Though there are many representations of spacing
which are not automatically quoted. E.g.,
$ touch $'f1,\u00A0f2' $ ls -m $'f1,\u00A0f2'
f1, f2
$ src/ls -m $'f1,\u00A0f2'
'f1, f2'
If a user at a shell was copying/pasting,
the original output may cause confusion.
ls usually isn't/shouldn't be programmatically parsed,
so this is mainly for interactive consideration.
I'm 60:40 for keeping the change.
I'll think a bit more about it,
and at least augment the test with the above example.
Note I'm also looking at a follow up patch to
disallow or more probably replace ',' and \n in names
when not quoting, to give better protection against
malicious names.
cheers,
Padraig