1
1
mirror of https://github.com/Kozea/WeasyPrint.git synced 2024-10-04 07:57:52 +03:00

Remove query strings from file:// URIs

Fix #687, fix #688.
This commit is contained in:
Guillaume Ayoub 2018-10-26 19:18:33 +02:00
parent 186c6550ed
commit 40f4e9af4c
2 changed files with 8 additions and 1 deletions

View File

@ -799,7 +799,8 @@ uses_relative.append('weasyprint-custom')
@assert_no_logs
def test_url_fetcher():
with open(resource_filename('pattern.png'), 'rb') as pattern_fd:
filename = resource_filename('pattern.png')
with open(filename, 'rb') as pattern_fd:
pattern_png = pattern_fd.read()
def fetcher(url):
@ -822,6 +823,8 @@ def test_url_fetcher():
check_png_pattern(html.write_png(stylesheets=[css]), blank=blank)
test('<body><img src="pattern.png">') # Test a "normal" URL
test('<body><img src="%s">' % Path(filename).as_uri())
test('<body><img src="%s?ignored">' % Path(filename).as_uri())
test('<body><img src="weasyprint-custom:foo/é_%e9_pattern">')
test('<body style="background: url(weasyprint-custom:foo/é_%e9_pattern)">')
test('<body><li style="list-style: inside '

View File

@ -232,6 +232,10 @@ def default_url_fetcher(url, timeout=10):
"""
if UNICODE_SCHEME_RE.match(url):
# See https://bugs.python.org/issue34702
if url.startswith('file://'):
url = url.split('?')[0]
url = iri_to_uri(url)
response = urlopen(Request(url, headers=HTTP_HEADERS), timeout=timeout)
response_info = response.info()