diff mercurial/windows.py @ 24885:eea3977e6fca stable

windows: make shellquote() quote any path containing '\' (issue4629) The '~' in the bug report is being expanded to a path with Windows style slashes before being passed to shellquote() via util.shellquote(). But shlex.split() strips '\' out of the string, leaving an invalid path in dispatch.aliasargs(). This regressed in 1642eb429536. For now, the tests need to be conditionalized for Windows (because those paths are quoted). In the future, a more complex regex could probably skip the quotes if all component separators are double '\'. I opted to glob away the quotes in test-rename-merge2.t and test-up-local-change.t (which only exist on Windows), because they are in very large blocks of output and there are way too many diffs to conditionalize with #if directives. Maybe the entire path should be globbed away like the following paths in each changed line. Or, letting #if directives sit in the middle of the output as was mentioned a few months back would work too. Unfortunately, I couldn't figure out how to test the specific bug. All of the 'hg serve' tests have a #require serve declaration, causing them to be skipped on Windows. Adding an alias for 'expandtest = outgoing ~/bogusrepo' prints the repo as '$TESTTMP/bogusrepo', so the test runner must be changing the environment somehow.
author Matt Harbison <matt_harbison@yahoo.com>
date Wed, 29 Apr 2015 21:14:59 -0400
parents 144883a8d0d4
children 30b910fea244
line wrap: on
line diff
--- a/mercurial/windows.py	Wed Apr 29 23:55:25 2015 -0400
+++ b/mercurial/windows.py	Wed Apr 29 21:14:59 2015 -0400
@@ -167,10 +167,12 @@
         _quotere = re.compile(r'(\\*)("|\\$)')
     global _needsshellquote
     if _needsshellquote is None:
-        # ":" and "\\" are also treated as "safe character", because
-        # 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
+        # ":" is also treated as "safe character", because it is used as a part
+        # of path name on Windows.  "\" is also part of a path name, but isn't
+        # safe because shlex.split() (kind of) treats it as an escape char and
+        # drops it.  It will leave the next character, even if it is another
+        # "\".
+        _needsshellquote = re.compile(r'[^a-zA-Z0-9._:/-]').search
     if s and not _needsshellquote(s) and not _quotere.search(s):
         # "s" shouldn't have to be quoted
         return s