From 94b65cef55c91c0139c2646f93b9bfc28dddfdf6 Mon Sep 17 00:00:00 2001 From: Eric Pheterson Date: Wed, 16 Sep 2026 08:03:32 -0700 Subject: [PATCH] Record the original for every rewritten URL attribute Widens the script-src case to src, href and xlink:href on any tag. wombat's getAttribute override looks for the recorded original first and otherwise calls extractOriginalURL, which can only reverse rewrites wombat itself performed. A value rewritten here is unrecognisable to it, so it prepends the original scheme to what is already a relative path. That is openzim/warc2zim#413 as well as #473: same cause, two symptoms. Needs the matching wombat change, since retrieveWBOSRC is SCRIPT-only until then and nothing reads the other attributes back. Measured on en.wikipedia.org/wiki/Whale (1,766 links): 152 attributes added, 0.9% larger gzipped. Most links are fragments or already relative and record nothing. poster is deliberately excluded: wombat rewrites it, this rewriter does not, so it would record nothing. --- src/zimscraperlib/rewriting/html.py | 94 +++++++++++++------------- tests/rewriting/test_html_rewriting.py | 55 +++++++++++---- 2 files changed, 89 insertions(+), 60 deletions(-) diff --git a/src/zimscraperlib/rewriting/html.py b/src/zimscraperlib/rewriting/html.py index 001ef84..25594e3 100644 --- a/src/zimscraperlib/rewriting/html.py +++ b/src/zimscraperlib/rewriting/html.py @@ -54,55 +54,55 @@ def get_attr_value_from( return default -# The attribute wombat reads a script's pre-rewrite src back out of. +# The attributes wombat asks for a pre-rewrite value of. # -# wombat already overrides Element.prototype.getAttribute and, for a ', @@ -1631,7 +1660,9 @@ def test_rewrite_meta_http_equiv_redirect_rule( ), ], ) -def test_script_keeps_its_original_src(input_str: str, expected_str: str): +def test_rewritten_url_attributes_keep_their_original( + input_str: str, expected_str: str +): """A rewritten