Skip to content

Commit 6057ba1

Browse files
committed
Fix Issue8656 - urllib2 mangles file://-scheme URLs
1 parent badc709 commit 6057ba1

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

Lib/test/test_urllib2.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ def test_file(self):
679679
try:
680680
data = r.read()
681681
headers = r.info()
682-
newurl = r.geturl()
682+
respurl = r.geturl()
683683
finally:
684684
r.close()
685685
stats = os.stat(TESTFN)
@@ -690,6 +690,7 @@ def test_file(self):
690690
self.assertEqual(headers["Content-type"], "text/plain")
691691
self.assertEqual(headers["Content-length"], "13")
692692
self.assertEqual(headers["Last-modified"], modified)
693+
self.assertEqual(respurl, url)
693694

694695
for url in [
695696
"file://localhost:80%s" % urlpath,

Lib/urllib2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ def open_local_file(self, req):
12911291
if not host or \
12921292
(not port and socket.gethostbyname(host) in self.get_names()):
12931293
return addinfourl(open(localfile, 'rb'),
1294-
headers, 'file:'+file)
1294+
headers, 'file://'+ host + file)
12951295
except OSError, msg:
12961296
# urllib2 users shouldn't expect OSErrors coming from urlopen()
12971297
raise URLError(msg)

0 commit comments

Comments
 (0)