Repository navigation
Resolve relative links against page URLs with consecutive slashes - #358
Conversation
|
@Sinkleberg / @anshuman83-40 I would be happy to have your feedback on this one. Cannot ask a formal review but would be happy to have an informal one ^^ Looks like there is no easy way besides re-implementing Python function ... |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #358 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 42 42
Lines 2817 2852 +35
Branches 416 428 +12
=========================================
+ Hits 2817 2852 +35 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thanks for picking this up! I had a look and it seems right to me:
About the coverage: in Small thing: |
|
Thanks for the thorough check! Pushed 5fdf31f addressing the coverage points:
Branch coverage on |
urllib.parse.urljoin collapses empty path segments while merging a relative reference onto the base URL, so a page whose own URL contains `//` had its relative links resolved to the wrong absolute URL (slashes collapsed before normalize() even saw them). Replace it with a custom join that follows RFC 3986 section 5.3 without that deviation, matching how browsers resolve such references. The JS (wombat) side already resolves relative URLs correctly via uri-js's URI.resolve, so only the Python rewriter needed a fix; added a regression test on the JS side to document that. Fix #346
_remove_dot_segments and _urljoin had a few branches that can never be hit given the merged path always starts with '/' and base is always a non-empty absolute URL, so drop them instead of leaving dead code around. Add a test for a query-only reference (e.g. "?page=2"), the one gap in branch coverage that was actually reachable. Also have the test helper _resolve_relative_reference reuse _remove_dot_segments instead of duplicating it.
Bare assert statements are stripped when Python runs with -O, so an internal contract violation would silently misbehave instead of failing loudly in that mode. Replace them with explicit raise AssertionError, in url_rewriting.py's _urljoin/_remove_dot_segments and in the pre-existing rx_replacer.py one, so the check always runs. Add tests covering each.
6d25d16 to
a576f69
Compare
Summary
ArticleUrlRewriterresolved relative links (andbase_href) withurllib.parse.urljoin, which collapses empty path segments while merging a relative reference onto the base URL. When a page's own URL contains//, this silently collapsed it beforenormalize()could see it, so the rewritten link pointed to an entry that doesn't exist in the ZIM.uri-js'sURI.resolve, which doesn't have this deviation, so no fix was needed there — added a regression test to document/lock in that behavior instead.Fix #346