]> granicus.if.org Git - python/commitdiff
Stricter verification for file based url scheme and reliance on ftp protocol.
authorSenthil Kumaran <orsenthil@gmail.com>
Sun, 11 Jul 2010 03:12:43 +0000 (03:12 +0000)
committerSenthil Kumaran <orsenthil@gmail.com>
Sun, 11 Jul 2010 03:12:43 +0000 (03:12 +0000)
Lib/test/test_urllib2.py
Lib/urllib/request.py

index 080daa4f2733a51a7c5f7e3ca519f425f25559f4..4d117c7319759f79dbda922fc5282e0eff508a72 100644 (file)
@@ -731,6 +731,8 @@ class HandlerTests(unittest.TestCase):
             ("file://ftp.example.com///foo.txt", False),
 # XXXX bug: fails with OSError, should be URLError
             ("file://ftp.example.com/foo.txt", False),
+            ("file://somehost//foo/something.txt", True),
+            ("file://localhost//foo/something.txt", False),
             ]:
             req = Request(url)
             try:
@@ -741,6 +743,7 @@ class HandlerTests(unittest.TestCase):
             else:
                 self.assertTrue(o.req is req)
                 self.assertEqual(req.type, "ftp")
+            self.assertEqual(req.type is "ftp", ftp)
 
     def test_http(self):
 
index f7c7416f34c1da7beac829f29f4b93010148edcf..c6767d0b26601bde5a1a6c11eacd07630fca1c3d 100644 (file)
@@ -1188,7 +1188,8 @@ class FileHandler(BaseHandler):
     # Use local file or FTP depending on form of URL
     def file_open(self, req):
         url = req.selector
-        if url[:2] == '//' and url[2:3] != '/':
+        if url[:2] == '//' and url[2:3] != '/' and (req.host and
+                req.host != 'localhost'):
             req.type = 'ftp'
             return self.parent.open(req)
         else: