change in urlopen behavior

Bug #937825 reported by Jamie Strandboge
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Python
Fix Released
Unknown
python2.7 (Ubuntu)
Fix Released
Medium
Unassigned

Bug Description

The fix for http://bugs.python.org/issue6631 that came in python2.7 2.7.2-13ubuntu5 may cause problems for people. Eg, in 2.7.2-13ubuntu4 this would work:
import urllib
url = "./foo.txt"
urllib.urlopen(url)

In 2.7.2-13ubuntu5 this code causes the following traceback:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/urllib.py", line 86, in urlopen
    return opener.open(url)
  File "/usr/lib/python2.7/urllib.py", line 207, in open
    return getattr(self, name)(url)
  File "/usr/lib/python2.7/urllib.py", line 462, in open_file
    return self.open_local_file(url)
  File "/usr/lib/python2.7/urllib.py", line 488, in open_local_file
    raise ValueError("local file url may start with / or file:. Unknown url of type: %s" % url)
ValueError: local file url may start with / or file:. Unknown url of type: ./foo.txt

While I have worked around it in the Ubuntu CVE tracker and this is not a blocker for my team, filing this bug as it may cause problems for others.

The workaround is simply to strip the './' off the front. Eg, a naive fix for the above might be:
import urllib
url = "./foo.txt"
if url.startswith('./'):
    url = url[2:]
urllib.urlopen(url)

description: updated
description: updated
description: updated
Matthias Klose (doko)
Changed in python2.7 (Ubuntu):
status: New → Confirmed
Changed in python:
status: Unknown → Fix Committed
Changed in python2.7 (Ubuntu):
importance: Undecided → Medium
Changed in python:
status: Fix Committed → Fix Released
Revision history for this message
Matthias Klose (doko) wrote :

closing this as fixed upstream for a long time

Changed in python2.7 (Ubuntu):
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.