Skip to content

Commit 5f92462

Browse files
authored
Merge pull request #216 from openzim/data_src
Handle case where JS module is an inline data
2 parents 42868f3 + 7d1b958 commit 5f92462

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/zimscraperlib/rewriting/html.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,11 @@ def rewrite_href_src_attributes(
602602
This is also notifying of any JS script found used as a module, so that this script
603603
is properly rewritten when encountered later on.
604604
"""
605-
if attr_name not in ("href", "src") or not attr_value:
605+
if (
606+
attr_name not in ("href", "src")
607+
or not attr_value
608+
or attr_value.startswith("data:")
609+
):
606610
return
607611
if (
608612
notify_js_module

tests/rewriting/test_html_rewriting.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,29 @@
6868
ContentForTests(input_="<!DOCTYPE html>A simple string with doctype"),
6969
ContentForTests(input_="A simple string with <!-- cc --> comment"),
7070
ContentForTests(input_="A simple string with <?xml ?> pi"),
71+
ContentForTests(
72+
input_='<script type="module" '
73+
'src="data:application/javascript;base64,QQQQ"></script>'
74+
),
7175
]
7276
)
7377
def no_rewrite_content(request: pytest.FixtureRequest):
7478
yield request.param
7579

7680

7781
def test_no_rewrite(no_rewrite_content: ContentForTests):
82+
83+
def noop_notify(zim_path: ZimPath):
84+
pass
85+
7886
assert (
7987
HtmlRewriter(
80-
ArticleUrlRewriter(
88+
url_rewriter=ArticleUrlRewriter(
8189
article_url=HttpUrl(f"http://{no_rewrite_content.article_url}"),
8290
),
83-
None,
84-
None,
85-
None,
91+
pre_head_insert=None,
92+
post_head_insert=None,
93+
notify_js_module=noop_notify,
8694
)
8795
.rewrite(no_rewrite_content.input_str)
8896
.content

0 commit comments

Comments
 (0)