url: store and assume the query part of an url is in escaped form (issue2921) stable
authorBenoit Boissinot <benoit.boissinot@ens-lyon.org>
Sun, 31 Jul 2011 21:00:44 +0200
branchstable
changeset 14988 e6730f9e13bc
parent 14981 192e02680d09
child 14989 9e9d4a762586
url: store and assume the query part of an url is in escaped form (issue2921)
mercurial/util.py
--- a/mercurial/util.py	Wed Jul 27 18:32:54 2011 -0400
+++ b/mercurial/util.py	Sun Jul 31 21:00:44 2011 +0200
@@ -1468,8 +1468,9 @@
 
         self.path = path
 
+        # leave the query string escaped
         for a in ('user', 'passwd', 'host', 'port',
-                  'path', 'query', 'fragment'):
+                  'path', 'fragment'):
             v = getattr(self, a)
             if v is not None:
                 setattr(self, a, _urlunquote(v))
@@ -1490,6 +1491,10 @@
 
         >>> str(url('http://user:pw@host:80/?foo#bar'))
         'http://user:pw@host:80/?foo#bar'
+        >>> str(url('http://user:pw@host:80/?foo=bar&baz=42'))
+        'http://user:pw@host:80/?foo=bar&baz=42'
+        >>> str(url('http://user:pw@host:80/?foo=bar%3dbaz'))
+        'http://user:pw@host:80/?foo=bar%3dbaz'
         >>> str(url('ssh://user:pw@[::1]:2200//home/joe#'))
         'ssh://user:pw@[::1]:2200//home/joe#'
         >>> str(url('http://localhost:80//'))
@@ -1538,9 +1543,13 @@
         if self.host:
             s += '/'
         if self.path:
+            # TODO: similar to the query string, we should not unescape the
+            # path when we store it, the path might contain '%2f' = '/',
+            # which we should *not* escape.
             s += urllib.quote(self.path, safe=self._safepchars)
         if self.query:
-            s += '?' + urllib.quote(self.query, safe=self._safepchars)
+            # we store the query in escaped form.
+            s += '?' + self.query
         if self.fragment is not None:
             s += '#' + urllib.quote(self.fragment, safe=self._safepchars)
         return s