]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Patch #1637: fix urlparse for URLs like 'http://x.com?arg=/foo'.
authorGuido van Rossum <guido@python.org>
Sat, 5 Jan 2008 22:19:06 +0000 (22:19 +0000)
committerGuido van Rossum <guido@python.org>
Sat, 5 Jan 2008 22:19:06 +0000 (22:19 +0000)
Fix by John Nagle.

Lib/test/test_urlparse.py
Lib/urlparse.py
Misc/NEWS

index bf9e31768494a03fa5a10461ead96e71bd77c70c..fff8408d60c8c149233a61829e3545b64004171b 100644 (file)
@@ -316,6 +316,11 @@ class UrlParseTestCase(unittest.TestCase):
         self.assertEqual(type(p.hostname), type(uri))
         self.assertEqual(type(p.path), type(uri))
 
+    def test_noslash(self):
+        # Issue 1637: http://foo.com?query is legal
+        self.assertEqual(urlparse.urlparse("http://example.com?blahblah=/foo"),
+                         ('http', 'example.com', '', '', 'blahblah=/foo', ''))
+
 def test_main():
     test_support.run_unittest(UrlParseTestCase)
 
index 4bf0af3d0c6bd6ef26792b2e3b879169f48270eb..7a2e6ce746141c21b908a1209770a5e1c07b60af 100644 (file)
@@ -169,13 +169,12 @@ def _splitparams(url):
     return url[:i], url[i+1:]
 
 def _splitnetloc(url, start=0):
-    for c in '/?#': # the order is important!
-        delim = url.find(c, start)
-        if delim >= 0:
-            break
-    else:
-        delim = len(url)
-    return url[start:delim], url[delim:]
+    delim = len(url)   # position of end of domain part of url, default is end
+    for c in '/?#':    # look for delimiters; the order is NOT important
+        wdelim = url.find(c, start)        # find first of this delim
+        if wdelim >= 0:                    # if found
+            delim = min(delim, wdelim)     # use earliest delim position
+    return url[start:delim], url[delim:]   # return (domain, rest)
 
 def urlsplit(url, scheme='', allow_fragments=True):
     """Parse a URL into 5 components:
index c5b0e244198faf295f377302a8f7f4af2d48119b..cf54566a3eeb0e4b565e48b36e87b14877edfc32 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -342,6 +342,8 @@ Core and builtins
 Library
 -------
 
+- Patch #1637: fix urlparse for URLs like 'http://x.com?arg=/foo'.
+
 - Patch #1698: allow '@' in username parsed by urlparse.py.
 
 - Issue #1735: TarFile.extractall() now correctly sets directory permissions