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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Patch vendored `wombat.js` so `retrieveWBOSRCAsURL` (the helper behind the above element-property fix) resolves a recorded original against the frame's true original URL (`wb_info.url`) instead of its replay-time `ownerDocument`, fixing it returning/using a URL under the wrong host for a page whose own URL was changed by a fuzzy rule (e.g. YouTube embeds), which broke playback (#398)
- Add a host-gated `SITE_JS_PATCHES` mechanism to `JsRewriter`, fixing MDN's `<interactive-example>` widget missing a deterministic `permalink` attribute (#394)

### Changed

- Re-enable `test_indexing_item_not_front` and test libzim's current indexing behavior for non-front items, including non-front `text/html` ones (#400)

## [5.5.2] - 2026-11-06

### Fixed
Expand Down
70 changes: 61 additions & 9 deletions tests/zim/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ def test_indexing_item_is_front(tmp_path: pathlib.Path, png_image: pathlib.Path)
assert reader.get_search_results_count("food") == 0


@pytest.mark.skip # see https://github.com/openzim/python-scraperlib/issues/258
def test_indexing_item_not_front(tmp_path: pathlib.Path, png_image: pathlib.Path):
"""Create a ZIM with a non-front item with custom title and content for indexing"""
fpath = tmp_path / "test.zim"
main_path = "welcome"
with Creator(fpath, main_path).config_dev_metadata() as creator:
Expand All @@ -139,21 +139,73 @@ def test_indexing_item_not_front(tmp_path: pathlib.Path, png_image: pathlib.Path
assert fpath.exists()

reader = Archive(fpath)
# "brain" works as a suggestion but "food" doesn't work because since no front
# article is present in the zim file, libzim doesn't create a title xapian index.
# so, when searching suggestion, libzim is fallback to a binary search on the title
# and return only article starting by the query.
# see https://github.com/openzim/libzim/issues/902#issuecomment-2223050129
assert "welcome" in list(reader.get_suggestions("brain"))
# libzim 3.13 yields no suggestions for a non-front item.
# This test documents libzim's current behaviour.
assert "welcome" not in list(reader.get_suggestions("brain"))
assert "welcome" not in list(reader.get_suggestions("food"))
assert "welcome" not in list(reader.get_suggestions("screen"))
assert "welcome" not in list(reader.get_suggestions("car"))
assert reader.get_search_results_count("screen") >= 1
assert reader.get_search_results_count("car") >= 1
assert reader.get_search_results_count("screen") == 1
assert reader.get_search_results_count("car") == 1
assert reader.get_search_results_count("brain") == 0
assert reader.get_search_results_count("food") == 0


def test_indexing_html_not_front_custom(tmp_path: pathlib.Path):
"""A non-front HTML item has custom indexing data"""
fpath = tmp_path / "test.zim"
main_path = "welcome"
with Creator(fpath, main_path).config_dev_metadata() as creator:
creator.add_item(
StaticItem(
content="<html><body>car</body></html>",
path="welcome",
title="brain food",
mimetype="text/html",
index_data=IndexData(title="screen", content="car"),
hints={libzim.writer.Hint.FRONT_ARTICLE: False},
)
)
assert fpath.exists()

reader = Archive(fpath)
assert "welcome" not in list(reader.get_suggestions("brain"))
assert "welcome" not in list(reader.get_suggestions("food"))
assert "welcome" not in list(reader.get_suggestions("screen"))
assert "welcome" not in list(reader.get_suggestions("car"))
assert reader.get_search_results_count("screen") == 1
assert reader.get_search_results_count("car") == 1
assert reader.get_search_results_count("brain") == 0
assert reader.get_search_results_count("food") == 0


def test_indexing_html_not_front_with_libzim(tmp_path: pathlib.Path):
"""A non-front HTML item is automatically indexed by libzim"""
fpath = tmp_path / "test.zim"
main_path = "welcome"
with Creator(fpath, main_path).config_dev_metadata() as creator:
creator.add_item(
StaticItem(
content="<html><title>screen</title><body>car</body></html>",
path="welcome",
title="brain food",
mimetype="text/html",
hints={libzim.writer.Hint.FRONT_ARTICLE: False},
)
)
assert fpath.exists()

reader = Archive(fpath)
assert "welcome" not in list(reader.get_suggestions("brain"))
assert "welcome" not in list(reader.get_suggestions("food"))
assert "welcome" not in list(reader.get_suggestions("screen"))
assert "welcome" not in list(reader.get_suggestions("car"))
assert reader.get_search_results_count("brain") == 1
assert reader.get_search_results_count("food") == 1
assert reader.get_search_results_count("car") == 1
assert reader.get_search_results_count("screen") == 0


def _assert_pdf_zim(fpath: pathlib.Path):
assert fpath.exists()

Expand Down