Subject: bug#63142: 30.0.50; QUOTING_STYLE can break dired

From: Eli Zaretskii <[email-masked]>
Date: Sat, 29 Apr 2023 13:46:54 +0300

> From: Yuri D'Elia <[email-masked]>
> Cc: [email-masked]
> Date: Fri, 28 Apr 2023 20:01:01 +0200
> 
> So searching through coreutils I find this old report:
> 
> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=23024
> 
> | On further analysis I see that --dired mode already distinguishes
> | the quoting-style in its output.  Also we had already documented
> | that --dired should specify a --quoting-style to get consistent output.
> 
> Which huh, does mention this in the ls manual:
> 
> | If you use a quoting style like ‘--quoting-style=c’ (‘-Q’) that
> |  adds quote marks, then the offsets include the quote marks.  So
> |  beware that the user may select the quoting style via the
> |  environment variable ‘QUOTING_STYLE’.  Hence, applications using
> |  ‘--dired’ should either specify an explicit
> |  ‘--quoting-style=literal’ (‘-N’) option on the command line, or
> |  else be prepared to parse the escaped names.
> 
> Then it references a commit mentioning an emacs fix:
> 
> https://github.com/emacs-mirror/emacs/commit/e4adb6
> 
> which however seems to apply to tramp only.

Does the patch below give good results?

diff --git a/lisp/dired.el b/lisp/dired.el
index d1471e9..e3a9d7b 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -1653,7 +1653,10 @@ dired-insert-directory
 see `dired-use-ls-dired' for more details.")
 		       nil))
 	       dired-use-ls-dired)))
-	(setq switches (concat "--dired " switches)))
+        ;; Use -N with --dired, to countermand possible non-default
+        ;; quoting style, in particular via the environment variable
+        ;; QUOTINTG_STYLE.
+	(setq switches (concat "--dired -N " switches)))
     ;; Expand directory wildcards and fill file-list.
     (let ((dir-wildcard (insert-directory-wildcard-in-dir-p dir)))
       (cond (dir-wildcard