Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/util.py @ 14988:e6730f9e13bc stable
url: store and assume the query part of an url is in escaped form (issue2921)
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Sun, 31 Jul 2011 21:00:44 +0200 |
parents | 28edd65000d9 |
children | f6a737357195 e89f62dcd723 |
comparison
equal
deleted
inserted
replaced
14981:192e02680d09 | 14988:e6730f9e13bc |
---|---|
1466 self.host not in ('localhost', '127.0.0.1', '[::1]')): | 1466 self.host not in ('localhost', '127.0.0.1', '[::1]')): |
1467 raise Abort(_('file:// URLs can only refer to localhost')) | 1467 raise Abort(_('file:// URLs can only refer to localhost')) |
1468 | 1468 |
1469 self.path = path | 1469 self.path = path |
1470 | 1470 |
1471 # leave the query string escaped | |
1471 for a in ('user', 'passwd', 'host', 'port', | 1472 for a in ('user', 'passwd', 'host', 'port', |
1472 'path', 'query', 'fragment'): | 1473 'path', 'fragment'): |
1473 v = getattr(self, a) | 1474 v = getattr(self, a) |
1474 if v is not None: | 1475 if v is not None: |
1475 setattr(self, a, _urlunquote(v)) | 1476 setattr(self, a, _urlunquote(v)) |
1476 | 1477 |
1477 def __repr__(self): | 1478 def __repr__(self): |
1488 | 1489 |
1489 Examples: | 1490 Examples: |
1490 | 1491 |
1491 >>> str(url('http://user:pw@host:80/?foo#bar')) | 1492 >>> str(url('http://user:pw@host:80/?foo#bar')) |
1492 'http://user:pw@host:80/?foo#bar' | 1493 'http://user:pw@host:80/?foo#bar' |
1494 >>> str(url('http://user:pw@host:80/?foo=bar&baz=42')) | |
1495 'http://user:pw@host:80/?foo=bar&baz=42' | |
1496 >>> str(url('http://user:pw@host:80/?foo=bar%3dbaz')) | |
1497 'http://user:pw@host:80/?foo=bar%3dbaz' | |
1493 >>> str(url('ssh://user:pw@[::1]:2200//home/joe#')) | 1498 >>> str(url('ssh://user:pw@[::1]:2200//home/joe#')) |
1494 'ssh://user:pw@[::1]:2200//home/joe#' | 1499 'ssh://user:pw@[::1]:2200//home/joe#' |
1495 >>> str(url('http://localhost:80//')) | 1500 >>> str(url('http://localhost:80//')) |
1496 'http://localhost:80//' | 1501 'http://localhost:80//' |
1497 >>> str(url('http://localhost:80/')) | 1502 >>> str(url('http://localhost:80/')) |
1536 if self.port: | 1541 if self.port: |
1537 s += ':' + urllib.quote(self.port) | 1542 s += ':' + urllib.quote(self.port) |
1538 if self.host: | 1543 if self.host: |
1539 s += '/' | 1544 s += '/' |
1540 if self.path: | 1545 if self.path: |
1546 # TODO: similar to the query string, we should not unescape the | |
1547 # path when we store it, the path might contain '%2f' = '/', | |
1548 # which we should *not* escape. | |
1541 s += urllib.quote(self.path, safe=self._safepchars) | 1549 s += urllib.quote(self.path, safe=self._safepchars) |
1542 if self.query: | 1550 if self.query: |
1543 s += '?' + urllib.quote(self.query, safe=self._safepchars) | 1551 # we store the query in escaped form. |
1552 s += '?' + self.query | |
1544 if self.fragment is not None: | 1553 if self.fragment is not None: |
1545 s += '#' + urllib.quote(self.fragment, safe=self._safepchars) | 1554 s += '#' + urllib.quote(self.fragment, safe=self._safepchars) |
1546 return s | 1555 return s |
1547 | 1556 |
1548 def authinfo(self): | 1557 def authinfo(self): |