Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bd3e771

Browse files
author
Michael W. Hudson
committed
amk's fix attached to
[ 516299 ] urlparse can get fragments wrong
1 parent 5c137c2 commit bd3e771

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

Lib/test/output/test_urlparse

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
test_urlparse
2+
http://www.python.org = ('http', 'www.python.org', '', '', '', '')
3+
http://www.python.org#abc = ('http', 'www.python.org', '', '', '', 'abc')
4+
http://www.python.org/#abc = ('http', 'www.python.org', '/', '', '', 'abc')
5+
http://a/b/c/d;p?q#f = ('http', 'a', '/b/c/d', 'p', 'q', 'f')
6+
27
urlparse.urljoin() tests
38

49
g:h = 'g:h'

Lib/test/test_urlparse.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@
44

55
RFC1808_BASE = "http://a/b/c/d;p?q#f"
66

7+
for url, expected in [('http://www.python.org',
8+
('http', 'www.python.org', '', '', '', '')),
9+
('http://www.python.org#abc',
10+
('http', 'www.python.org', '', '', '', 'abc')),
11+
('http://www.python.org/#abc',
12+
('http', 'www.python.org', '/', '', '', 'abc')),
13+
(RFC1808_BASE,
14+
('http', 'a', '/b/c/d', 'p', 'q', 'f')),
15+
]:
16+
result = urlparse.urlparse(url)
17+
print "%-13s = %r" % (url, result)
18+
if result != expected:
19+
errors += 1
20+
print "urlparse(%r)" % url
21+
print ("expected %r,\n"
22+
" got %r") % (expected, result)
23+
print
24+
725
def checkJoin(relurl, expected):
826
global errors
927
result = urlparse.urljoin(RFC1808_BASE, relurl)

Lib/urlparse.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ def urlsplit(url, scheme='', allow_fragments=1):
8787
if url[:2] == '//':
8888
i = url.find('/', 2)
8989
if i < 0:
90-
i = len(url)
90+
i = url.find('#')
91+
if i < 0:
92+
i = len(url)
9193
netloc = url[2:i]
9294
url = url[i:]
9395
if allow_fragments and '#' in url:

0 commit comments

Comments
 (0)