]> granicus.if.org Git - python/commitdiff
amk's fix attached to
authorMichael W. Hudson <mwh@python.net>
Mon, 18 Mar 2002 13:06:00 +0000 (13:06 +0000)
committerMichael W. Hudson <mwh@python.net>
Mon, 18 Mar 2002 13:06:00 +0000 (13:06 +0000)
[ 516299 ] urlparse can get fragments wrong

Lib/test/output/test_urlparse
Lib/test/test_urlparse.py
Lib/urlparse.py

index ca71729e7ff25b79ef4bc85ef751ce2da1a3f328..c478783295b1cb97c236284e0fef79e6fcd11594 100644 (file)
@@ -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'
index 20336bc7081867c8fac28bbbb7a02a3706299c3b..48c526bf394599b9d5d7ff424a7e213277e7e468 100644 (file)
@@ -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)
index cd6ad26dae70277b0baee0535b552f60c4a31125..ee99645d59b7ce3937021c203a6c8b3fd16c5953 100644 (file)
@@ -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: