Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Carry a script's top-level `const`, `let` and `class` declarations across the wombat block, so other scripts on the page can still see them (#329)
- Keep a rewritten `<script>`'s original `src` in `__wb_orig_src`, so wombat can return it from `getAttribute("src")` and bundlers that identify chunks by it (Next.js/Turbopack, Vite) still work (openzim/warc2zim#473)
- Keep URL-encoded `#` characters of the path or querystring when rewriting document URIs, instead of dropping everything after them (#341)

## [5.4.1] - 2026-07-31

Expand Down
4 changes: 3 additions & 1 deletion src/zimscraperlib/rewriting/url_rewriting.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@ def get_document_uri(self, item_path: ZimPath, item_fragment: str) -> str:
URI.

"""
item_parts = urlsplit(item_path.value)
# a ZIM path is never URL-encoded, so a `#` in it is a literal character
# (e.g. coming from a `%23` in original URL) and not a fragment delimiter
item_parts = urlsplit(item_path.value, allow_fragments=False)

# item_path is both path + querystring, both will be url-encoded in the document
# so that readers consider them as a whole and properly pass them to libzim
Expand Down
33 changes: 33 additions & 0 deletions tests/rewriting/test_url_rewriting.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,39 @@ def test_missing_zim_paths(
["kiwix.org/a/article/foo.html?foo=b?ar"],
False,
),
(
"https://kiwix.org/a/article/document.html",
"foo%23bar.html", # a path with an encoded # char
RewriteResult(
"https://kiwix.org/a/article/foo%23bar.html",
"foo%23bar.html",
ZimPath("kiwix.org/a/article/foo#bar.html"),
),
["kiwix.org/a/article/foo#bar.html"],
False,
),
(
"https://kiwix.org/a/article/document.html",
"foo%23bar.html#anchor1", # encoded # char followed by a fragment
RewriteResult(
"https://kiwix.org/a/article/foo%23bar.html#anchor1",
"foo%23bar.html#anchor1",
ZimPath("kiwix.org/a/article/foo#bar.html"),
),
["kiwix.org/a/article/foo#bar.html"],
False,
),
(
"https://kiwix.org/a/article/document.html",
"foo.html?foo=b%23ar", # a query string with an encoded # char
RewriteResult(
"https://kiwix.org/a/article/foo.html?foo=b%23ar",
"foo.html%3Ffoo=b%23ar",
ZimPath("kiwix.org/a/article/foo.html?foo=b#ar"),
),
["kiwix.org/a/article/foo.html?foo=b#ar"],
False,
),
(
"https://kiwix.org/a/article/document.html",
"fo%o.html",
Expand Down