diff mercurial/windows.py @ 38724:02b5b5c1bba8

windows: replace single quote with double quote when translating to cmd.exe Since cmd.exe doesn't understand single quotes, single quotes to prevent $var expansion is basically unusable without this. Single quote isn't allowed in a path name, so it seems unlikely to come up otherwise.
author Matt Harbison <matt_harbison@yahoo.com>
date Sun, 15 Jul 2018 23:58:39 -0400
parents 93ed193bc03e
children c382c19ce9bd
line wrap: on
line diff
--- a/mercurial/windows.py	Sun Jul 15 23:51:43 2018 -0400
+++ b/mercurial/windows.py	Sun Jul 15 23:58:39 2018 -0400
@@ -268,7 +268,7 @@
     'cmd %var1% %var2% %var3% $missing ${missing} %missing%'
     >>> # Single quote prevents expansion, as does \$ escaping
     >>> shelltocmdexe(b"cmd '$var1 ${var2} %var3%' \$var1 \${var2} \\", e)
-    "cmd '$var1 ${var2} %var3%' $var1 ${var2} \\"
+    'cmd "$var1 ${var2} %var3%" $var1 ${var2} \\'
     >>> # $$ is not special. %% is not special either, but can be the end and
     >>> # start of consecutive variables
     >>> shelltocmdexe(b"cmd $$ %% %var1%%var2%", e)
@@ -277,7 +277,7 @@
     >>> shelltocmdexe(b"$var1 %var1%", {b'var1': b'%var2%', b'var2': b'boom'})
     '%var1% %var1%'
     """
-    if b'$' not in path:
+    if not any(c in path for c in b"$'"):
         return path
 
     varchars = pycompat.sysbytes(string.ascii_letters + string.digits) + b'_-'
@@ -292,7 +292,7 @@
             pathlen = len(path)
             try:
                 index = path.index(b'\'')
-                res += b'\'' + path[:index + 1]
+                res += b'"' + path[:index] + b'"'
             except ValueError:
                 res += c + path
                 index = pathlen - 1