changeset 1976:df8416346bb7

Enable path validation for copy, rename, debugwalk and other canonpath users. This fixed the last bit of issue134. Added some tests to test-rename and test-walk.
author Thomas Arendsen Hein <thomas@intevation.de>
date Sun, 19 Mar 2006 14:53:58 +0100
parents 6e1a8ea5d717
children 7eb694a1c1af
files mercurial/util.py tests/test-rename tests/test-rename.out tests/test-walk tests/test-walk.out
diffstat 5 files changed, 65 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -185,7 +185,9 @@ def canonpath(root, cwd, myname):
         name = os.path.join(root, cwd, name)
     name = os.path.normpath(name)
     if name.startswith(rootsep):
-        return pconvert(name[len(rootsep):])
+        name = name[len(rootsep):]
+        audit_path(name)
+        return pconvert(name)
     elif name == root:
         return ''
     else:
--- a/tests/test-rename
+++ b/tests/test-rename
@@ -179,3 +179,33 @@ hg rename d1/bb d1/b
 hg status
 hg debugstate | grep copy
 hg update -C
+
+echo "# check illegal path components"
+
+hg rename d1/d11/a1 .hg/foo
+hg status
+hg rename d1/d11/a1 ../foo
+hg status
+
+mv d1/d11/a1 .hg/foo
+hg rename --after d1/d11/a1 .hg/foo
+hg status
+hg update -C
+rm .hg/foo
+
+hg rename d1/d11/a1 .hg
+hg status
+hg rename d1/d11/a1 ..
+hg status
+
+mv d1/d11/a1 .hg
+hg rename --after d1/d11/a1 .hg
+hg status
+hg update -C
+rm .hg/a1
+
+(cd d1/d11; hg rename ../../d2/b ../../.hg/foo)
+hg status
+(cd d1/d11; hg rename ../../d2/b ../../../foo)
+hg status
+
--- a/tests/test-rename.out
+++ b/tests/test-rename.out
@@ -254,3 +254,19 @@ A d1/bc
 R d1/b
 # idempotent renames (d1/b -> d1/bb followed by d1/bb -> d1/b)
 M d1/b
+# check illegal path components
+abort: path contains illegal component: .hg/foo
+
+abort: ../foo not under root
+abort: path contains illegal component: .hg/foo
+
+! d1/d11/a1
+abort: path contains illegal component: .hg/a1
+
+abort: ../a1 not under root
+abort: path contains illegal component: .hg/a1
+
+! d1/d11/a1
+abort: path contains illegal component: .hg/foo
+
+abort: ../../../foo not under root
--- a/tests/test-walk
+++ b/tests/test-walk
@@ -28,6 +28,8 @@ hg debugwalk ..
 cd ..
 hg debugwalk ../beans
 hg debugwalk .
+hg debugwalk .hg
+hg debugwalk ../.hg
 cd ..
 hg debugwalk -Ibeans
 hg debugwalk 'glob:mammals/../beans/b*'
@@ -35,6 +37,10 @@ hg debugwalk '-X*/Procyonidae' mammals
 hg debugwalk path:mammals
 hg debugwalk ..
 hg debugwalk beans/../..
+hg debugwalk .hg
+hg debugwalk beans/../.hg
+hg debugwalk beans/../.hg/data
+hg debugwalk beans/.hg
 # Don't know how to test absolute paths without always getting a false
 # error.
 #hg debugwalk `pwd`/beans
--- a/tests/test-walk.out
+++ b/tests/test-walk.out
@@ -50,6 +50,9 @@ f  mammals/Procyonidae/cacomistle  Procy
 f  mammals/Procyonidae/coatimundi  Procyonidae/coatimundi
 f  mammals/Procyonidae/raccoon     Procyonidae/raccoon
 f  mammals/skunk                   skunk
+.hg: No such file or directory
+abort: path contains illegal component: .hg
+
 f  beans/black     beans/black
 f  beans/borlotti  beans/borlotti
 f  beans/kidney    beans/kidney
@@ -65,6 +68,13 @@ f  mammals/Procyonidae/raccoon     mamma
 f  mammals/skunk                   mammals/skunk
 abort: .. not under root
 abort: beans/../.. not under root
+abort: path contains illegal component: .hg
+
+abort: path contains illegal component: .hg
+
+abort: path contains illegal component: .hg/data
+
+beans/.hg: No such file or directory
 f  fennel      fennel
 f  fenugreek   fenugreek
 f  fiddlehead  fiddlehead