Escape '%' when writing to hgrc (issue1199)
authorBenoit Boissinot <benoit.boissinot@ens-lyon.org>
Sat, 20 Sep 2008 15:00:58 +0200
changeset 7044 e51c0f41f271
parent 7043 b714aac1f7b3
child 7045 f82938c87b92
child 7048 25961e53a07f
Escape '%' when writing to hgrc (issue1199) Fixes clone with paths containing '%'. Patch provided by mjc.
mercurial/hg.py
tests/test-hgrc
tests/test-hgrc.out
--- a/mercurial/hg.py	Thu Sep 18 13:55:58 2008 +0200
+++ b/mercurial/hg.py	Sat Sep 20 15:00:58 2008 +0200
@@ -239,7 +239,8 @@
         if dest_repo.local():
             fp = dest_repo.opener("hgrc", "w", text=True)
             fp.write("[paths]\n")
-            fp.write("default = %s\n" % abspath)
+            # percent needs to be escaped for ConfigParser
+            fp.write("default = %s\n" % abspath.replace('%', '%%'))
             fp.close()
 
             if update:
--- a/tests/test-hgrc	Thu Sep 18 13:55:58 2008 +0200
+++ b/tests/test-hgrc	Sat Sep 20 15:00:58 2008 +0200
@@ -5,3 +5,14 @@
 hg init
 echo "invalid" > .hg/hgrc
 hg status 2>&1 |sed -e "s:/.*\(/t/.*\):...\1:"
+
+#issue 1199, escaping
+
+cd ..
+hg init "foo%bar"
+hg clone "foo%bar" foobar
+p=`pwd`
+cd foobar
+cat .hg/hgrc |sed -e "s:$p:...:"
+hg paths |sed -e "s:$p:...:"
+hg showconfig |sed -e "s:$p:...:"
--- a/tests/test-hgrc.out	Thu Sep 18 13:55:58 2008 +0200
+++ b/tests/test-hgrc.out	Sat Sep 20 15:00:58 2008 +0200
@@ -2,3 +2,15 @@
 File contains no section headers.
 file: .../t/.hg/hgrc, line: 1
 'invalid\n'
+updating working directory
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+[paths]
+default = .../foo%%bar
+default = .../foo%bar
+bundle.mainreporoot=.../foobar
+defaults.backout=-d "0 0"
+defaults.commit=-d "0 0"
+defaults.debugrawcommit=-d "0 0"
+defaults.tag=-d "0 0"
+paths.default=.../foo%bar
+ui.slash=True