diff options
author | Senthil Kumaran <orsenthil@gmail.com> | 2010-11-20 11:24:08 (GMT) |
---|---|---|
committer | Senthil Kumaran <orsenthil@gmail.com> | 2010-11-20 11:24:08 (GMT) |
commit | 9fce551e0e630f8da454b77d46264d812ba57f46 (patch) | |
tree | 51e17454cef3b313c62b975b57f6be15c3992409 | |
parent | 6be0e9fa905bf22fc8ef1df0b57d7b9cef5cf525 (diff) | |
download | cpython-9fce551e0e630f8da454b77d46264d812ba57f46.zip cpython-9fce551e0e630f8da454b77d46264d812ba57f46.tar.gz cpython-9fce551e0e630f8da454b77d46264d812ba57f46.tar.bz2 |
Merged revisions 86520 via svnmerge from
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
........
-rw-r--r-- | Lib/test/test_urllib2.py | 20 | ||||
-rw-r--r-- | Lib/urllib.py | 6 | ||||
-rw-r--r-- | Lib/urllib2.py | 4 |
3 files changed, 20 insertions, 10 deletions
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 8703081..983ffa8 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -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) diff --git a/Lib/urllib.py b/Lib/urllib.py index 9c58923..d85dedb 100644 --- a/Lib/urllib.py +++ b/Lib/urllib.py @@ -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 diff --git a/Lib/urllib2.py b/Lib/urllib2.py index adc6d8c..7d90db2 100644 --- a/Lib/urllib2.py +++ b/Lib/urllib2.py @@ -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) |