Skip to content

Fix JS URL rewriter confusing %2B with raw + in query strings - #390

Merged
benoit74 merged 1 commit into
mainfrom
benoit74/fix-wombat-plus-query-encoding
Nov 8, 2026
Merged

benoit74 merged 1 commit into
mainfrom
benoit74/fix-wombat-plus-query-encoding

Conversation

@benoit74

@benoit74 benoit74 commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • wombatSetup.js's urlRewriteFunction decoded the query string with decodeURIComponent() before replacing + with ' '. A literal + correctly percent-encoded as %2B (meaning "a real plus sign") got turned back into a raw + by the decode step, then immediately collapsed into a space by the replace — indistinguishable from a genuinely raw, unencoded + (which means "space", by convention, same as Python's url_rewriting.py already implements).
  • Fixed by applying the + -> ' ' substitution on the still-encoded query string, before decoding — matching the order the Python implementation already uses.
  • Added two JS tests making the distinction explicit (contentWithQueryValueRawPlusSign / contentWithQueryValueEncodedPlusSign).

Fixes #389, found while finishing verification of #387/#388 (openzim/warc2zim#327): MDN's "Try it" live-sample iframes build their URL with a base64-encoded state query parameter, which legitimately contains + characters. Those were corrupted into spaces, so the ZIM path computed from the rewritten URL no longer matched the WARC record, and the iframe 404'd instead of rendering the demo.

Verified against a real test ZIM built from a crawl of MDN's <section> reference page: with this fix (and #387/#388), the "Before"/"After" and "Using a section without a heading" live-sample demos now render their actual content instead of staying blank/404.

@codecov

codecov Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (13f4481) to head (a9c25a3).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #390   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           42        42           
  Lines         2937      2937           
  Branches       450       450           
=========================================
  Hits          2937      2937           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

wombatSetup.js decoded the query string with decodeURIComponent()
before replacing '+' with ' ', so a literal '+' that had been
correctly percent-encoded as '%2B' (meaning "real plus sign") got
turned back into '+' by the decode, then immediately smashed into a
space by the replace - indistinguishable from a raw, unencoded '+'
(which means "space", by convention). Apply the substitution on the
still-encoded query string instead, before decoding, matching the
order already used by the Python implementation (url_rewriting.py).

Found while verifying the fix for openzim/warc2zim#327: MDN's "Try
it" live-sample iframes use a base64-encoded `state` query parameter,
which legitimately contains '+' characters; those got corrupted into
spaces, so the ZIM path built from the rewritten URL no longer
matched the WARC record and the iframe 404'd. (#389)
@benoit74
benoit74 force-pushed the benoit74/fix-wombat-plus-query-encoding branch from c6c5a0d to a9c25a3 Compare November 8, 2026 20:44
@benoit74
benoit74 merged commit 940d1b2 into main Nov 8, 2026
8 checks passed
@benoit74
benoit74 deleted the benoit74/fix-wombat-plus-query-encoding branch November 8, 2026 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JS URL rewriter confuses a literal %2B with a raw + in query strings, turning both into a space

1 participant