GNU bug report logs - #6136
Emerge doesn't handle file names with spaces on MS Windows

Previous Next

Package: emacs;

Reported by: Joakim Hårsman <joakim.harsman <at> gmail.com>

Date: Fri, 7 May 2010 19:30:02 UTC

Severity: normal

Fixed in versions 23.3.90, 25.2

Done: npostavs <at> users.sourceforge.net

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 6136 in the body.
You can then email your comments to 6136 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#6136; Package emacs. (Fri, 07 May 2010 19:30:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Joakim Hårsman <joakim.harsman <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 07 May 2010 19:30:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Joakim Hårsman <joakim.harsman <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Emerge doesn't handle file names with spaces on MS Windows
Date: Fri, 7 May 2010 21:19:36 +0200
If any of the file names supplied to Emerge (e.g to
emerge-files-with-ancestor) has spaces in in its path and Emacs is
running on MS Windows, the merge fails.

The problem is the way Emerge passes the file names to diff, it tries
to escape spaces (and other metchars) with backslashes, but that
doesn't work on MS Windows since the backslash is a path separator
there.

If I change the definition of emerge-protect-metachars to the
following it works:

(defun emerge-protect-metachars (s)
  (if (member system-type '(windows-nt ms-dos))
      (emerge-protect-metachars-win s)
    (emerge-protect-metachars-nix s)))

(defun emerge-protect-metachars-nix (s)
  (let ((limit 0))
    (while (string-match emerge-metachars s limit)
      (setq s (concat (substring s 0 (match-beginning 0))
		      "\\"
		      (substring s (match-beginning 0))))
      (setq limit (1+ (match-end 0)))))
  s)

(defun emerge-protect-metachars-win (s)
  (concat "\"" s "\""))


Here's some output which might be useful:
GNU Emacs 23.1.1 (i386-mingw-nt5.1.2600) of 2009-07-30 on SOFT-MJASON





Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#6136; Package emacs. (Sat, 08 May 2010 15:11:02 GMT) Full text and rfc822 format available.

Message #8 received at 6136 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Joakim Hårsman <joakim.harsman <at> gmail.com>
Cc: 6136 <at> debbugs.gnu.org
Subject: Re: bug#6136: Emerge doesn't handle file names with spaces on MS
	Windows
Date: Sat, 08 May 2010 18:08:01 +0300
> Date: Fri, 7 May 2010 21:19:36 +0200
> From: Joakim Hårsman <joakim.harsman <at> gmail.com>
> Cc: 
> 
> If any of the file names supplied to Emerge (e.g to
> emerge-files-with-ancestor) has spaces in in its path and Emacs is
> running on MS Windows, the merge fails.
> 
> The problem is the way Emerge passes the file names to diff, it tries
> to escape spaces (and other metchars) with backslashes, but that
> doesn't work on MS Windows since the backslash is a path separator
> there.
> 
> If I change the definition of emerge-protect-metachars to the
> following it works:
> 
> (defun emerge-protect-metachars (s)
>   (if (member system-type '(windows-nt ms-dos))
>       (emerge-protect-metachars-win s)
>     (emerge-protect-metachars-nix s)))
> 
> (defun emerge-protect-metachars-nix (s)
>   (let ((limit 0))
>     (while (string-match emerge-metachars s limit)
>       (setq s (concat (substring s 0 (match-beginning 0))
> 		      "\\"
> 		      (substring s (match-beginning 0))))
>       (setq limit (1+ (match-end 0)))))
>   s)
> 
> (defun emerge-protect-metachars-win (s)
>   (concat "\"" s "\""))

I think emerge-protect-metachars should simply use
shell-quote-argument, on all platforms.  Then it won't need to
distinguish between the different flavors, and it won't need to know
which characters need protection, something that is shell-dependent
and thus tricky even on Unix.

Could you try a patch along those line, and see if it works?





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#6136; Package emacs. (Sat, 06 Aug 2016 14:07:01 GMT) Full text and rfc822 format available.

Message #11 received at 6136 <at> debbugs.gnu.org (full text, mbox):

From: npostavs <at> users.sourceforge.net
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 6136 <at> debbugs.gnu.org,
 Joakim Hårsman <joakim.harsman <at> gmail.com>
Subject: Re: bug#6136: Emerge doesn't handle file names with spaces on MS
 Windows
Date: Sat, 06 Aug 2016 10:06:37 -0400
[Message part 1 (text/plain, inline)]
fixed 6136 23.3.90
quit

Was reported a second time
(http://article.gmane.org/gmane.emacs.help/80250) and then fixed by
576bce32 (2011-03-19 "Fix emerge.el on MS-Windows and MS-DOS...")

Eli Zaretskii <eliz <at> gnu.org> writes:

> I think emerge-protect-metachars should simply use
> shell-quote-argument, on all platforms.  Then it won't need to
> distinguish between the different flavors, and it won't need to know
> which characters need protection, something that is shell-dependent
> and thus tricky even on Unix.

But the non-Windows case still uses emerge-metachars.  Should we make it
same on all platforms:

[v1-0001-Make-emerge-always-use-shell-quote-argument.patch (text/plain, inline)]
From 7f960d1e91eb69ac14c55de2dc4a78adbf1274f1 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs <at> gmail.com>
Date: Sat, 6 Aug 2016 09:51:15 -0400
Subject: [PATCH v1] Make emerge always use shell-quote-argument

* lisp/vc/emerge.el (emerge-metachars): Obsolete.
(emerge-protect-metachars): Delete.
(emerge-make-diff-list, emerge-make-diff3-list): Replace all calls to
`emerge-protect-metachars' with `shell-quote-argument' so that shell
quoting is done the same on all system types (Bug #6136).  Also shell
quote `emerge-diff-program' and `emerge-diff3-program'.
---
 lisp/vc/emerge.el | 37 ++++++++++++-------------------------
 1 file changed, 12 insertions(+), 25 deletions(-)

diff --git a/lisp/vc/emerge.el b/lisp/vc/emerge.el
index de25cba..058b15c 100644
--- a/lisp/vc/emerge.el
+++ b/lisp/vc/emerge.el
@@ -621,9 +621,10 @@ emerge-make-diff-list
    (erase-buffer)
    (shell-command
     (format "%s %s %s %s"
-	    emerge-diff-program emerge-diff-options
-	    (emerge-protect-metachars file-A)
-	    (emerge-protect-metachars file-B))
+	    (shell-quote-argument emerge-diff-program)
+            emerge-diff-options
+	    (shell-quote-argument file-A)
+	    (shell-quote-argument file-B))
     t))
   (emerge-prepare-error-list emerge-diff-ok-lines-regexp)
   (emerge-convert-diffs-to-markers
@@ -792,10 +793,11 @@ emerge-make-diff3-list
    (erase-buffer)
    (shell-command
     (format "%s %s %s %s %s"
-	    emerge-diff3-program emerge-diff-options
-	    (emerge-protect-metachars file-A)
-	    (emerge-protect-metachars file-ancestor)
-	    (emerge-protect-metachars file-B))
+	    (shell-quote-argument emerge-diff3-program)
+            emerge-diff-options
+	    (shell-quote-argument file-A)
+	    (shell-quote-argument file-ancestor)
+	    (shell-quote-argument file-B))
     t))
   (emerge-prepare-error-list emerge-diff3-ok-lines-regexp)
   (emerge-convert-diffs-to-markers
@@ -3171,26 +3173,11 @@ emerge-unslashify-name
 
 ;; Metacharacters that have to be protected from the shell when executing
 ;; a diff/diff3 command.
-(defcustom emerge-metachars
-  (if (memq system-type '(ms-dos windows-nt))
-      "[ \t\"<>|?*^&=]"
-    "[ \t\n!\"#$&'()*;<=>?[\\^`{|~]")
-  "Characters that must be quoted when used in a shell command line.
-More precisely, a [...] regexp to match any one such character."
+(defcustom emerge-metachars nil
+  "Obsolete, emerge now uses `shell-quote-argument'."
   :type 'regexp
   :group 'emerge)
-
-;; Quote metacharacters (using \) when executing a diff/diff3 command.
-(defun emerge-protect-metachars (s)
-  (if (memq system-type '(ms-dos windows-nt))
-      (shell-quote-argument s)
-    (let ((limit 0))
-      (while (string-match emerge-metachars s limit)
-	(setq s (concat (substring s 0 (match-beginning 0))
-			"\\"
-			(substring s (match-beginning 0))))
-	(setq limit (1+ (match-end 0)))))
-    s))
+(make-obsolete-variable 'emerge-metachars nil "25.2")
 
 (provide 'emerge)
 
-- 
2.8.0


bug Marked as fixed in versions 23.3.90. Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Sat, 06 Aug 2016 14:07:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#6136; Package emacs. (Sat, 06 Aug 2016 14:47:02 GMT) Full text and rfc822 format available.

Message #16 received at 6136 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: npostavs <at> users.sourceforge.net
Cc: 6136 <at> debbugs.gnu.org, joakim.harsman <at> gmail.com
Subject: Re: bug#6136: Emerge doesn't handle file names with spaces on MS
 Windows
Date: Sat, 06 Aug 2016 17:46:36 +0300
> From: npostavs <at> users.sourceforge.net
> Cc: Joakim Hårsman <joakim.harsman <at> gmail.com>,
>   6136 <at> debbugs.gnu.org
> Date: Sat, 06 Aug 2016 10:06:37 -0400
> 
> Eli Zaretskii <eliz <at> gnu.org> writes:
> 
> > I think emerge-protect-metachars should simply use
> > shell-quote-argument, on all platforms.  Then it won't need to
> > distinguish between the different flavors, and it won't need to know
> > which characters need protection, something that is shell-dependent
> > and thus tricky even on Unix.
> 
> But the non-Windows case still uses emerge-metachars.  Should we make it
> same on all platforms:

Yes, I think so.

Thanks.




bug marked as fixed in version 25.2, send any further explanations to 6136 <at> debbugs.gnu.org and Joakim Hårsman <joakim.harsman <at> gmail.com> Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Sat, 06 Aug 2016 20:17:03 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 04 Sep 2016 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 8 years and 293 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.