]> granicus.if.org Git - python/commitdiff
Merged revisions 86520 via svnmerge from
authorSenthil Kumaran <orsenthil@gmail.com>
Sat, 20 Nov 2010 11:24:08 +0000 (11:24 +0000)
committerSenthil Kumaran <orsenthil@gmail.com>
Sat, 20 Nov 2010 11:24:08 +0000 (11:24 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r86520 | senthil.kumaran | 2010-11-18 23:36:41 +0800 (Thu, 18 Nov 2010) | 3 lines

  Fix Issue2244 - urllib unquotes user and password info multiple times - Patch by Theodore Turocy
........

Lib/test/test_urllib2.py
Lib/urllib.py
Lib/urllib2.py

index 87030819c5da51f37a89f8d0852066fa8463f2f4..983ffa8529bb3dc91bcfd1a02838610952162cf4 100644 (file)
@@ -622,22 +622,32 @@ class HandlerTests(unittest.TestCase):
         h = NullFTPHandler(data)
         o = h.parent = MockOpener()
 
-        for url, host, port, type_, dirs, filename, mimetype in [
+        for url, host, port, user, passwd, type_, dirs, filename, mimetype in [
             ("ftp://localhost/foo/bar/baz.html",
-             "localhost", ftplib.FTP_PORT, "I",
+             "localhost", ftplib.FTP_PORT, "", "", "I",
+             ["foo", "bar"], "baz.html", "text/html"),
+            ("ftp://parrot@localhost/foo/bar/baz.html",
+             "localhost", ftplib.FTP_PORT, "parrot", "", "I",
+             ["foo", "bar"], "baz.html", "text/html"),
+            ("ftp://%25parrot@localhost/foo/bar/baz.html",
+             "localhost", ftplib.FTP_PORT, "%parrot", "", "I",
+             ["foo", "bar"], "baz.html", "text/html"),
+            ("ftp://%2542parrot@localhost/foo/bar/baz.html",
+             "localhost", ftplib.FTP_PORT, "%42parrot", "", "I",
              ["foo", "bar"], "baz.html", "text/html"),
             ("ftp://localhost:80/foo/bar/",
-             "localhost", 80, "D",
+             "localhost", 80, "", "", "D",
              ["foo", "bar"], "", None),
             ("ftp://localhost/baz.gif;type=a",
-             "localhost", ftplib.FTP_PORT, "A",
+             "localhost", ftplib.FTP_PORT, "", "", "A",
              [], "baz.gif", None),  # XXX really this should guess image/gif
             ]:
             req = Request(url)
             req.timeout = None
             r = h.ftp_open(req)
             # ftp authentication not yet implemented by FTPHandler
-            self.assertTrue(h.user == h.passwd == "")
+            self.assertEqual(h.user, user)
+            self.assertEqual(h.passwd, passwd)
             self.assertEqual(h.host, socket.gethostbyname(host))
             self.assertEqual(h.port, port)
             self.assertEqual(h.dirs, dirs)
index 9c58923fc7a450308225b3d5d10062067f049660..d85dedbb647ac984da63ce864d641eaad623897f 100644 (file)
@@ -511,8 +511,8 @@ class URLopener:
         if user: user, passwd = splitpasswd(user)
         else: passwd = None
         host = unquote(host)
-        user = unquote(user or '')
-        passwd = unquote(passwd or '')
+        user = user or ''
+        passwd = passwd or ''
         host = socket.gethostbyname(host)
         if not port:
             import ftplib
@@ -1064,7 +1064,7 @@ def splituser(host):
         _userprog = re.compile('^(.*)@(.*)$')
 
     match = _userprog.match(host)
-    if match: return map(unquote, match.group(1, 2))
+    if match: return match.group(1, 2)
     return None, host
 
 _passwdprog = None
index adc6d8c55a92f32df988733d1e25b1820c97cf1a..7d90db20c99e88fee6fb775b66ab983b6c2b6ef2 100644 (file)
@@ -1349,8 +1349,8 @@ class FTPHandler(BaseHandler):
         else:
             passwd = None
         host = unquote(host)
-        user = unquote(user or '')
-        passwd = unquote(passwd or '')
+        user = user or ''
+        passwd = passwd or ''
 
         try:
             host = socket.gethostbyname(host)