Commits

Michael W. Hudson  committed 4668d1c

amk's fix attached to

[ 516299 ] urlparse can get fragments wrong

  • Participants
  • Parent commits 775da61
  • Branches 2.2

Comments (0)

Files changed (3)

File Lib/test/output/test_urlparse

 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'

File Lib/test/test_urlparse.py

 
 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)

File Lib/urlparse.py

             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: