Patchwork [stable] util: warn when adding paths ending with \

login
register
mail settings
Submitter Mads Kiilerich
Date Nov. 8, 2013, 11:35 a.m.
Message ID <5036bf9018a115da7f34.1383910555@mk-desktop>
Download mbox | patch
Permalink /patch/2890/
State Accepted
Commit 0849d280663e46b3e247857f4a68fabd2ba503c3
Headers show

Comments

Mads Kiilerich - Nov. 8, 2013, 11:35 a.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1383910550 -3600
#      Fri Nov 08 12:35:50 2013 +0100
# Branch stable
# Node ID 5036bf9018a115da7f34448d6fa6fc920622e5ef
# Parent  ba6486076429e5c20d910b8a5d4f8acf1e9dc1b1
util: warn when adding paths ending with \

Paths ending with \ will fail the verification introduced in 684a977c2ae0 when
checking out on Windows ... and if it didn't fail it would probably not do what
the user expected.
Matt Mackall - Nov. 8, 2013, 7:44 p.m.
On Fri, 2013-11-08 at 12:35 +0100, Mads Kiilerich wrote:
> # HG changeset patch
> # User Mads Kiilerich <madski@unity3d.com>
> # Date 1383910550 -3600
> #      Fri Nov 08 12:35:50 2013 +0100
> # Branch stable
> # Node ID 5036bf9018a115da7f34448d6fa6fc920622e5ef
> # Parent  ba6486076429e5c20d910b8a5d4f8acf1e9dc1b1
> util: warn when adding paths ending with \

Queued for stable, thanks.

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -563,7 +563,7 @@ 
     lpt1 lpt2 lpt3 lpt4 lpt5 lpt6 lpt7 lpt8 lpt9'''.split()
 _winreservedchars = ':*?"<>|'
 def checkwinfilename(path):
-    '''Check that the base-relative path is a valid filename on Windows.
+    r'''Check that the base-relative path is a valid filename on Windows.
     Returns None if the path is ok, or a UI string describing the problem.
 
     >>> checkwinfilename("just/a/normal/path")
@@ -577,11 +577,19 @@ 
     >>> checkwinfilename("foo/bar/bla:.txt")
     "filename contains ':', which is reserved on Windows"
     >>> checkwinfilename("foo/bar/b\07la.txt")
-    "filename contains '\\\\x07', which is invalid on Windows"
+    "filename contains '\\x07', which is invalid on Windows"
     >>> checkwinfilename("foo/bar/bla ")
     "filename ends with ' ', which is not allowed on Windows"
     >>> checkwinfilename("../bar")
+    >>> checkwinfilename("foo\\")
+    "filename ends with '\\', which is invalid on Windows"
+    >>> checkwinfilename("foo\\/bar")
+    "directory name ends with '\\', which is invalid on Windows"
     '''
+    if path.endswith('\\'):
+        return _("filename ends with '\\', which is invalid on Windows")
+    if '\\/' in path:
+        return _("directory name ends with '\\', which is invalid on Windows")
     for n in path.replace('\\', '/').split('/'):
         if not n:
             continue