Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3242577

Browse files
committed
merge from 3.2
2 parents 77fc1f3 + 3800ea9 commit 3242577

4 files changed

Lines changed: 8 additions & 2 deletions

File tree

Lib/test/test_urllib.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ def test_iter(self):
160160
for line in self.returned_obj:
161161
self.assertEqual(line, self.text)
162162

163+
def test_relativelocalfile(self):
164+
self.assertRaises(ValueError,urllib.request.urlopen,'./' + self.pathname)
165+
163166
class ProxyTests(unittest.TestCase):
164167

165168
def setUp(self):

Lib/test/test_urllib2net.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ def test_file(self):
125125
finally:
126126
os.remove(TESTFN)
127127

128+
self.assertRaises(ValueError, urllib.request.urlopen,'./relative_path/to/file')
129+
128130
# XXX Following test depends on machine configurations that are internal
129131
# to CNRI. Need to set up a public server with the right authentication
130132
# configuration for test purposes.

Lib/urllib/request.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,6 +1813,8 @@ def open_local_file(self, url):
18131813
urlfile = file
18141814
if file[:1] == '/':
18151815
urlfile = 'file://' + file
1816+
elif file[:2] == './':
1817+
raise ValueError("local file url may start with / or file:. Unknown url of type: %s" % url)
18161818
return addinfourl(open(localname, 'rb'), headers, urlfile)
18171819
raise URLError('local file error', 'not on local host')
18181820

Misc/NEWS

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,7 @@ Core and Builtins
453453
Library
454454
-------
455455

456-
- Issue #2134: A new attribute that specifies the exact type of token.OP
457-
tokens has been added to tokenize.TokenInfo.
456+
- Issue #6631: Disallow relative file paths in urllib urlopen methods.
458457

459458
- Issue #13722: Avoid silencing ImportErrors when initializing the codecs
460459
registry.

0 commit comments

Comments
 (0)