Skip to content

Commit 40f4e9a

Browse files
committed
Remove query strings from file:// URIs
Fix #687, fix #688.
1 parent 186c655 commit 40f4e9a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

weasyprint/tests/test_api.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,8 @@ def assert_links(html, expected_links_by_page, expected_anchors_by_page,
799799

800800
@assert_no_logs
801801
def test_url_fetcher():
802-
with open(resource_filename('pattern.png'), 'rb') as pattern_fd:
802+
filename = resource_filename('pattern.png')
803+
with open(filename, 'rb') as pattern_fd:
803804
pattern_png = pattern_fd.read()
804805

805806
def fetcher(url):
@@ -822,6 +823,8 @@ def test(html, blank=False):
822823
check_png_pattern(html.write_png(stylesheets=[css]), blank=blank)
823824

824825
test('<body><img src="pattern.png">') # Test a "normal" URL
826+
test('<body><img src="%s">' % Path(filename).as_uri())
827+
test('<body><img src="%s?ignored">' % Path(filename).as_uri())
825828
test('<body><img src="weasyprint-custom:foo/é_%e9_pattern">')
826829
test('<body style="background: url(weasyprint-custom:foo/é_%e9_pattern)">')
827830
test('<body><li style="list-style: inside '

weasyprint/urls.py

+4
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ def default_url_fetcher(url, timeout=10):
232232
233233
"""
234234
if UNICODE_SCHEME_RE.match(url):
235+
# See https://bugs.python.org/issue34702
236+
if url.startswith('file://'):
237+
url = url.split('?')[0]
238+
235239
url = iri_to_uri(url)
236240
response = urlopen(Request(url, headers=HTTP_HEADERS), timeout=timeout)
237241
response_info = response.info()

0 commit comments

Comments
 (0)