Mercurial > public > mercurial-scm > hg
comparison mercurial/url.py @ 13815:d066d8d652c8
url: add trailing slashes to URLs with hostnames that don't have one
This works around a potential issue in Python 2.4 where cloning a repo
with a URL like http://foo:8080 would cause urllib2 to query on
http://foo:8080?cmd=capabilities instead of
http://foo:8080/?cmd=capabilities.
In the past, this issue has been masked by the fact that
url.getauthinfo() added a trailing slash when it was missing.
author | Brodie Rao <brodie@bitheap.org> |
---|---|
date | Wed, 30 Mar 2011 20:00:23 -0700 |
parents | 03dfe0c85c1a |
children | 2540f8087e02 |
comparison
equal
deleted
inserted
replaced
13814:03dfe0c85c1a | 13815:d066d8d652c8 |
---|---|
154 >>> str(url('http://localhost:80//')) | 154 >>> str(url('http://localhost:80//')) |
155 'http://localhost:80//' | 155 'http://localhost:80//' |
156 >>> str(url('http://localhost:80/')) | 156 >>> str(url('http://localhost:80/')) |
157 'http://localhost:80/' | 157 'http://localhost:80/' |
158 >>> str(url('http://localhost:80')) | 158 >>> str(url('http://localhost:80')) |
159 'http://localhost:80' | 159 'http://localhost:80/' |
160 >>> str(url('bundle:foo')) | 160 >>> str(url('bundle:foo')) |
161 'bundle:foo' | 161 'bundle:foo' |
162 >>> str(url('path')) | 162 >>> str(url('path')) |
163 'path' | 163 'path' |
164 """ | 164 """ |
183 s += urllib.quote(self.host) | 183 s += urllib.quote(self.host) |
184 else: | 184 else: |
185 s += self.host | 185 s += self.host |
186 if self.port: | 186 if self.port: |
187 s += ':' + urllib.quote(self.port) | 187 s += ':' + urllib.quote(self.port) |
188 if ((self.host and self.path is not None) or | 188 if self.host: |
189 (self.host and self.query or self.fragment)): | |
190 s += '/' | 189 s += '/' |
191 if self.path: | 190 if self.path: |
192 s += urllib.quote(self.path, safe=self._safepchars) | 191 s += urllib.quote(self.path, safe=self._safepchars) |
193 if self.query: | 192 if self.query: |
194 s += '?' + urllib.quote(self.query, safe=self._safepchars) | 193 s += '?' + urllib.quote(self.query, safe=self._safepchars) |