changeset 24108:d65ecb814fc0 stable

shellquote: fix missing quotes for empty string "hg kdiff3 -rREV" did not work because 1642eb429536 and 5edb387158a1 failed to handle empty argument.
author Yuya Nishihara <yuya@tcha.org>
date Wed, 11 Feb 2015 19:57:07 +0900
parents 942a5a34b2d0
children 31bedb15e2e5
files mercurial/posix.py mercurial/windows.py tests/test-extdiff.t
diffstat 3 files changed, 18 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/posix.py	Mon Feb 02 14:26:47 2015 -0500
+++ b/mercurial/posix.py	Wed Feb 11 19:57:07 2015 +0900
@@ -322,7 +322,7 @@
     global _needsshellquote
     if _needsshellquote is None:
         _needsshellquote = re.compile(r'[^a-zA-Z0-9._/-]').search
-    if not _needsshellquote(s):
+    if s and not _needsshellquote(s):
         # "s" shouldn't have to be quoted
         return s
     else:
--- a/mercurial/windows.py	Mon Feb 02 14:26:47 2015 -0500
+++ b/mercurial/windows.py	Wed Feb 11 19:57:07 2015 +0900
@@ -159,7 +159,7 @@
         # they are used as a part of path name (and the latter doesn't
         # work as "escape character", like one on posix) on Windows
         _needsshellquote = re.compile(r'[^a-zA-Z0-9._:/\\-]').search
-    if not _needsshellquote(s) and not _quotere.search(s):
+    if s and not _needsshellquote(s) and not _quotere.search(s):
         # "s" shouldn't have to be quoted
         return s
     return '"%s"' % _quotere.sub(r'\1\1\\\2', s)
--- a/tests/test-extdiff.t	Mon Feb 02 14:26:47 2015 -0500
+++ b/tests/test-extdiff.t	Wed Feb 11 19:57:07 2015 +0900
@@ -182,6 +182,22 @@
   running "*/bin/echo --foo='sp ace' 'sp ace' --bar='sp ace' 'sp ace'" in * (glob)
 #endif
 
+Empty argument must be quoted
+
+  $ cat <<EOF >> $HGRCPATH
+  > [extdiff]
+  > kdiff3 = echo
+  > [merge-tools]
+  > kdiff3.diffargs=--L1 \$plabel1 --L2 \$clabel \$parent \$child
+  > EOF
+#if windows
+  $ hg --debug kdiff3 -r0 | grep '^running'
+  running 'echo --L1 "@0" --L2 "" a.8a5febb7f867 a' in * (glob)
+#else
+  $ hg --debug kdiff3 -r0 | grep '^running'
+  running "echo --L1 '@0' --L2 '' a.8a5febb7f867 a" in * (glob)
+#endif
+
 #if execbit
 
 Test extdiff of multiple files in tmp dir: