[PATCH 2 of 2] audit: simplify checking for .hg

Peter Arrenbrecht peter.arrenbrecht at gmail.com
Fri Jan 9 01:13:30 CST 2009


# HG changeset patch
# User Peter Arrenbrecht <peter.arrenbrecht at gmail.com>
# Date 1231144792 -3600
# Node ID 69efd4a3f03ca4e7344134f35ded399a93ce2007
# Parent  603ac785a1b0c5fbed3d7ad770eae56e54f6882c
audit: simplify checking for .hg

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -814,15 +814,17 @@
             return
         normpath = os.path.normcase(path)
         parts = splitpath(normpath)
-        if (os.path.splitdrive(path)[0] or parts[0] in ('.hg', '.hg.', '')
-            or os.pardir in parts):
+        if os.path.splitdrive(path)[0] or parts[0] == '' or os.pardir in parts:
             raise Abort(_("path contains illegal component: %s") % path)
         if '.hg' in path:
             for p in '.hg', '.hg.':
                 if p in parts:
                     pos = parts.index(p)
-                    base = os.path.join(*parts[:pos])
-                    raise Abort(_('path %r is inside repo %r') % (path, base))
+                    if pos:
+                        base = os.path.join(*parts[:pos])
+                        raise Abort(_('path %r is inside repo %r') % (path, base))
+                    else:
+                        raise Abort(_('path %r starts with illegal path component: %r') % (path, p))
         def check(prefix):
             curpath = os.path.join(self.root, prefix)
             try:
diff --git a/tests/test-audit-path.out b/tests/test-audit-path.out
--- a/tests/test-audit-path.out
+++ b/tests/test-audit-path.out
@@ -1,5 +1,5 @@
 % should fail
-abort: path contains illegal component: .hg/00changelog.i
+abort: path '.hg/00changelog.i' starts with illegal path component: '.hg'
 adding a/a
 % should fail
 abort: path 'b/b' traverses symbolic link 'b'
@@ -14,7 +14,7 @@
 (run 'hg heads' to see heads, 'hg merge' to merge)
 % attack .hg/test
 .hg/test
-abort: path contains illegal component: .hg/test
+abort: path '.hg/test' starts with illegal path component: '.hg'
 % attack foo/.hg/test
 foo/.hg/test
 abort: path 'foo/.hg/test' is inside repo 'foo'


More information about the Mercurial-devel mailing list