diff options
author | Michael W. Hudson <mwh@python.net> | 2002-03-18 13:03:40 (GMT) |
---|---|---|
committer | Michael W. Hudson <mwh@python.net> | 2002-03-18 13:03:40 (GMT) |
commit | 1c136f35dd36328c67f40d651303fe1e4c20ea84 (patch) | |
tree | d1d7586a1d11c8b099b7f723f1b0b38a46ff715f | |
parent | 39d2b3c33047b25f91387e09a3986df2b5c753b3 (diff) | |
download | cpython-1c136f35dd36328c67f40d651303fe1e4c20ea84.zip cpython-1c136f35dd36328c67f40d651303fe1e4c20ea84.tar.gz cpython-1c136f35dd36328c67f40d651303fe1e4c20ea84.tar.bz2 |
amk's fix attached to
[ 516299 ] urlparse can get fragments wrong
-rw-r--r-- | Lib/test/output/test_urlparse | 5 | ||||
-rw-r--r-- | Lib/test/test_urlparse.py | 18 | ||||
-rw-r--r-- | Lib/urlparse.py | 4 |
3 files changed, 26 insertions, 1 deletions
diff --git a/Lib/test/output/test_urlparse b/Lib/test/output/test_urlparse index ca71729..c478783 100644 --- a/Lib/test/output/test_urlparse +++ b/Lib/test/output/test_urlparse @@ -1,4 +1,9 @@ test_urlparse +http://www.python.org = ('http', 'www.python.org', '', '', '', '') +http://www.python.org#abc = ('http', 'www.python.org', '', '', '', 'abc') +http://www.python.org/#abc = ('http', 'www.python.org', '/', '', '', 'abc') +http://a/b/c/d;p?q#f = ('http', 'a', '/b/c/d', 'p', 'q', 'f') + urlparse.urljoin() tests g:h = 'g:h' diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py index 20336bc..48c526b 100644 --- a/Lib/test/test_urlparse.py +++ b/Lib/test/test_urlparse.py @@ -4,6 +4,24 @@ errors = 0 RFC1808_BASE = "http://a/b/c/d;p?q#f" +for url, expected in [('http://www.python.org', + ('http', 'www.python.org', '', '', '', '')), + ('http://www.python.org#abc', + ('http', 'www.python.org', '', '', '', 'abc')), + ('http://www.python.org/#abc', + ('http', 'www.python.org', '/', '', '', 'abc')), + (RFC1808_BASE, + ('http', 'a', '/b/c/d', 'p', 'q', 'f')), + ]: + result = urlparse.urlparse(url) + print "%-13s = %r" % (url, result) + if result != expected: + errors += 1 + print "urlparse(%r)" % url + print ("expected %r,\n" + " got %r") % (expected, result) +print + def checkJoin(relurl, expected): global errors result = urlparse.urljoin(RFC1808_BASE, relurl) diff --git a/Lib/urlparse.py b/Lib/urlparse.py index cd6ad26..ee99645 100644 --- a/Lib/urlparse.py +++ b/Lib/urlparse.py @@ -87,7 +87,9 @@ def urlsplit(url, scheme='', allow_fragments=1): if url[:2] == '//': i = url.find('/', 2) if i < 0: - i = len(url) + i = url.find('#') + if i < 0: + i = len(url) netloc = url[2:i] url = url[i:] if allow_fragments and '#' in url: |