Patchwork [2,of,3] windows: strip double quotes from the command to be found in findexe()

login
register
mail settings
Submitter Matt Harbison
Date Feb. 21, 2018, 4:32 a.m.
Message ID <8d7c512d216042abc6df.1519187573@Envy>
Download mbox | patch
Permalink /patch/28176/
State Accepted
Headers show

Comments

Matt Harbison - Feb. 21, 2018, 4:32 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1519181569 18000
#      Tue Feb 20 21:52:49 2018 -0500
# Node ID 8d7c512d216042abc6df7653ad6981275880ec45
# Parent  50a2885e94783ecce0820a08dd40d26cadbf0ae1
windows: strip double quotes from the command to be found in findexe()

After 94a1ff16f362 stopped unconditionally using posix style shlex.split(), the
quotes remained around the editor path in debuginstall, so the string wasn't
found in PATH.  This seems a little more robust than fixing it in the debug
command (and more consistent with how cmd.exe searches).
Yuya Nishihara - Feb. 21, 2018, 11:31 a.m.
On Tue, 20 Feb 2018 23:32:53 -0500, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1519181569 18000
> #      Tue Feb 20 21:52:49 2018 -0500
> # Node ID 8d7c512d216042abc6df7653ad6981275880ec45
> # Parent  50a2885e94783ecce0820a08dd40d26cadbf0ae1
> windows: strip double quotes from the command to be found in findexe()
> 
> After 94a1ff16f362 stopped unconditionally using posix style shlex.split(), the
> quotes remained around the editor path in debuginstall, so the string wasn't
> found in PATH.  This seems a little more robust than fixing it in the debug
> command (and more consistent with how cmd.exe searches).
> 
> diff --git a/mercurial/windows.py b/mercurial/windows.py
> --- a/mercurial/windows.py
> +++ b/mercurial/windows.py
> @@ -324,6 +324,9 @@
>      PATH isn't searched if command is an absolute or relative path.
>      An extension from PATHEXT is found and added if not present.
>      If command isn't found None is returned.'''
> +    if command[0] == '"' and command[-1] == '"':
> +        command = command[1:-1]

I think findexe() is designed to take an exact command name, not a command-line
string. It's probably better to handle quotes by caller.

Patch

diff --git a/mercurial/windows.py b/mercurial/windows.py
--- a/mercurial/windows.py
+++ b/mercurial/windows.py
@@ -324,6 +324,9 @@ 
     PATH isn't searched if command is an absolute or relative path.
     An extension from PATHEXT is found and added if not present.
     If command isn't found None is returned.'''
+    if command[0] == '"' and command[-1] == '"':
+        command = command[1:-1]
+
     pathext = encoding.environ.get('PATHEXT', '.COM;.EXE;.BAT;.CMD')
     pathexts = [ext for ext in pathext.lower().split(pycompat.ospathsep)]
     if os.path.splitext(command)[1].lower() in pathexts: