From: Senthil Kumaran <orsenthil@gmail.com>
Date: Fri, 17 Dec 2010 04:48:45 +0000 (+0000)
Subject: Fix Issue9721 - urljoin behavior when the relative url starts with ';'
X-Git-Tag: v3.2b2~46
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dca5b862338034460e060cedee8ba788073e20b3;p=python

Fix Issue9721 - urljoin behavior when the relative url starts with ';'
---

diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py
index 73e4de580b..f9f97b110b 100644
--- a/Lib/test/test_urlparse.py
+++ b/Lib/test/test_urlparse.py
@@ -327,6 +327,9 @@ class UrlParseTestCase(unittest.TestCase):
         #self.checkJoin(RFC3986_BASE, 'http:g','http:g') # strict parser
         self.checkJoin(RFC3986_BASE, 'http:g','http://a/b/c/g') #relaxed parser
 
+        # Test for issue9721
+        self.checkJoin('http://a/b/c/de', ';x','http://a/b/c/;x')
+
     def test_urljoins(self):
         self.checkJoin(SIMPLE_BASE, 'g:h','g:h')
         self.checkJoin(SIMPLE_BASE, 'http:g','http://a/b/c/g')
diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py
index eedd071113..42f8193682 100644
--- a/Lib/urllib/parse.py
+++ b/Lib/urllib/parse.py
@@ -411,14 +411,9 @@ def urljoin(base, url, allow_fragments=True):
     if path[:1] == '/':
         return _coerce_result(urlunparse((scheme, netloc, path,
                                           params, query, fragment)))
-    if not path:
+    if not path and not params:
         path = bpath
-        if not params:
-            params = bparams
-        else:
-            path = path[:-1]
-            return _coerce_result(urlunparse((scheme, netloc, path,
-                                              params, query, fragment)))
+        params = bparams
         if not query:
             query = bquery
         return _coerce_result(urlunparse((scheme, netloc, path,
diff --git a/Misc/NEWS b/Misc/NEWS
index 19611dd20b..1fce06c155 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -19,6 +19,8 @@ Core and Builtins
 
 Library
 -------
+- Issue #9721: Fix the behavior of urljoin when the relative url starts with a
+  ';' character. Patch by Wes Chow.
 
 - Issue #10714: Limit length of incoming request in http.server to 65536 bytes
   for security reasons.  Initial patch by Ross Lagerwall.