]> granicus.if.org Git - python/commitdiff
Fix Issue6631 - Disallow relative files paths in urllib*.open()
authorSenthil Kumaran <senthil@uthcode.com>
Sat, 21 Jan 2012 03:43:02 +0000 (11:43 +0800)
committerSenthil Kumaran <senthil@uthcode.com>
Sat, 21 Jan 2012 03:43:02 +0000 (11:43 +0800)
Lib/test/test_urllib.py
Lib/test/test_urllib2net.py
Lib/urllib.py

index 085eecf0f609033c56d1445ba9a521ca837e950f..91aeb2f11666e54fca1e618d177bce1d74ff1419 100644 (file)
@@ -134,6 +134,9 @@ class urlopen_FileTests(unittest.TestCase):
         for line in self.returned_obj.__iter__():
             self.assertEqual(line, self.text)
 
+    def test_relativelocalfile(self):
+        self.assertRaises(ValueError,urllib.urlopen,'./' + self.pathname)
+
 class ProxyTests(unittest.TestCase):
 
     def setUp(self):
index bd2c46772e9d10e0e36cf0f51de5e0256f9cb21a..dcdbfe87c66450ebf9d70304af783b94f7c90215 100644 (file)
@@ -126,6 +126,8 @@ class OtherNetworkTests(unittest.TestCase):
         finally:
             os.remove(TESTFN)
 
+        self.assertRaises(ValueError, urllib2.urlopen,'./relative_path/to/file')
+
     # XXX Following test depends on machine configurations that are internal
     # to CNRI.  Need to set up a public server with the right authentication
     # configuration for test purposes.
index c7af8ec4fd987610984df94be032735ef60b1a72..a73c5d7ba518ccbcd771ad82f39edb37bb1f0cd9 100644 (file)
@@ -484,6 +484,8 @@ class URLopener:
             urlfile = file
             if file[:1] == '/':
                 urlfile = 'file://' + file
+            elif file[:2] == './':
+                raise ValueError("local file url may start with / or file:. Unknown url of type: %s" % url)
             return addinfourl(open(localname, 'rb'),
                               headers, urlfile)
         host, port = splitport(host)