diff options
author | Senthil Kumaran <senthil@uthcode.com> | 2014-07-22 07:15:20 (GMT) |
---|---|---|
committer | Senthil Kumaran <senthil@uthcode.com> | 2014-07-22 07:15:20 (GMT) |
commit | bc07ac51801ae261ce09f057cbb4ecf9b7cdc07c (patch) | |
tree | 967f2c71f50f19a82f0a87434c0e477dfcc88cd2 | |
parent | dfab935c74745133234dded912ec1b0721888505 (diff) | |
download | cpython-bc07ac51801ae261ce09f057cbb4ecf9b7cdc07c.zip cpython-bc07ac51801ae261ce09f057cbb4ecf9b7cdc07c.tar.gz cpython-bc07ac51801ae261ce09f057cbb4ecf9b7cdc07c.tar.bz2 |
Fix localhost checking in FileHandler. Raised in #21970.
-rw-r--r-- | Lib/test/test_urllib2.py | 3 | ||||
-rw-r--r-- | Lib/urllib/request.py | 2 |
2 files changed, 3 insertions, 2 deletions
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 6b73723..7620876 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -678,7 +678,7 @@ class HandlerTests(unittest.TestCase): self.assertEqual(int(headers["Content-length"]), len(data)) def test_file(self): - import email.utils, socket + import email.utils h = urllib.request.FileHandler() o = h.parent = MockOpener() @@ -725,6 +725,7 @@ class HandlerTests(unittest.TestCase): for url in [ "file://localhost:80%s" % urlpath, "file:///file_does_not_exist.txt", + "file://not-a-local-host.com//dir/file.txt", "file://%s:80%s/%s" % (socket.gethostbyname('localhost'), os.getcwd(), TESTFN), "file://somerandomhost.ontheinternet.com%s/%s" % diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index 72e91dd..0389f5e 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -1315,7 +1315,7 @@ class FileHandler(BaseHandler): url = req.selector if url[:2] == '//' and url[2:3] != '/' and (req.host and req.host != 'localhost'): - if not req.host is self.get_names(): + if not req.host in self.get_names(): raise URLError("file:// scheme is supported only on localhost") else: return self.open_local_file(req) |