Have abshref() return unparseable hrefs unchanged

This commit is contained in:
Kovid Goyal 2016-10-13 09:13:01 +05:30
parent 3c26bc1075
commit b3ec54636d
2 changed files with 8 additions and 4 deletions

View File

@ -1108,7 +1108,10 @@ class Manifest(object):
"""Convert the URL provided in :param:`href` from a reference
relative to this manifest item to a book-absolute reference.
"""
purl = urlparse(href)
try:
purl = urlparse(href)
except ValueError:
return href
scheme = purl.scheme
if scheme and scheme != 'file':
return href

View File

@ -97,7 +97,10 @@ def name_to_href(name, root, base=None, quote=urlquote):
def href_to_name(href, root, base=None):
base = root if base is None else os.path.dirname(name_to_abspath(base, root))
purl = urlparse(href)
try:
purl = urlparse(href)
except ValueError:
return None
if purl.scheme or not purl.path:
return None
href = urlunquote(purl.path)
@ -1458,5 +1461,3 @@ def test_roundtrip():
if __name__ == '__main__':
test_roundtrip()