(original) (raw)
changeset: 91755:4b98961748f1 branch: 3.4 parent: 91752:4dac45f88d45 user: Senthil Kumaran senthil@uthcode.com date: Tue Jul 22 00:15:20 2014 -0700 files: Lib/test/test_urllib2.py Lib/urllib/request.py description: Fix localhost checking in FileHandler. Raised in #21970. diff -r 4dac45f88d45 -r 4b98961748f1 Lib/test/test_urllib2.py --- a/Lib/test/test_urllib2.py Mon Jul 21 18:35:01 2014 -0400 +++ b/Lib/test/test_urllib2.py Tue Jul 22 00:15:20 2014 -0700 @@ -678,7 +678,7 @@ 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 @@ 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 -r 4dac45f88d45 -r 4b98961748f1 Lib/urllib/request.py --- a/Lib/urllib/request.py Mon Jul 21 18:35:01 2014 -0400 +++ b/Lib/urllib/request.py Tue Jul 22 00:15:20 2014 -0700 @@ -1315,7 +1315,7 @@ 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) /senthil@uthcode.com