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	Sat Mar 18 09:51:25 2006 -0800
+++ b/mercurial/util.py	Sun Mar 19 14:53:58 2006 +0100
@@ -185,7 +185,9 @@
         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	Sat Mar 18 09:51:25 2006 -0800
+++ b/tests/test-rename	Sun Mar 19 14:53:58 2006 +0100
@@ -179,3 +179,33 @@
 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	Sat Mar 18 09:51:25 2006 -0800
+++ b/tests/test-rename.out	Sun Mar 19 14:53:58 2006 +0100
@@ -254,3 +254,19 @@
 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	Sat Mar 18 09:51:25 2006 -0800
+++ b/tests/test-walk	Sun Mar 19 14:53:58 2006 +0100
@@ -28,6 +28,8 @@
 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 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	Sat Mar 18 09:51:25 2006 -0800
+++ b/tests/test-walk.out	Sun Mar 19 14:53:58 2006 +0100
@@ -50,6 +50,9 @@
 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/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