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 @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Keep escaped Unicode characters in CSS strings instead of turning them into literal characters when rewriting (#377)
- Patch vendored `wombat.js` so element properties (`img.src`, `script.src`, `link.href`, `a.href` and its derived `.pathname`/`.search`/..., `Attr.value`) return and forget a server-side-rewriter-recorded original the same way `getAttribute` already does (#386, webrecorder/wombat#240)
- Detect `export const`/`let`/`var`/`function`/`async function`/`*` as module code (`EXPORT_RX` only recognized `export {...}`, `export default` and `export class`), fixing JS rewriting wrongly injecting a non-module `let arguments;` wrapper into ES modules using these common export forms, which is a syntax error in strict/module code (#387)
- Fix JS URL rewriter confusing a percent-encoded `%2B` with a raw `+` in query strings (#389)
- 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)

## [5.5.2] - 2026-11-06
Expand Down
8 changes: 6 additions & 2 deletions javascript/src/wombatSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,15 @@ export function urlRewriteFunction(
: decodeURIComponent(absolute_url_parts.path);

// And the decoded query, only exception is that + sign must resolve to ' ' to avoid
// confusion (our convention, just like in Python)
// confusion (our convention, just like in Python). The `+` -> ' ' substitution must
// happen on the still-encoded query string, before decoding percent-escapes,
// otherwise a value containing a literal `+` correctly percent-encoded as `%2B`
// would get wrongly turned into a space once decodeURIComponent turns it back into
// a raw `+` (same order as the Python implementation).
const decoded_query =
!absolute_url_parts.query || absolute_url_parts.query.length === 0
? ''
: '?' + decodeURIComponent(absolute_url_parts.query).replaceAll('+', ' ');
: '?' + decodeURIComponent(absolute_url_parts.query.replaceAll('+', ' '));

// combine all decoded parts to get the ZIM path
// (consecutive slashes are kept, just like in Python)
Expand Down
40 changes: 40 additions & 0 deletions javascript/test/wombatUrlRewriting.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,46 @@ test('contentWithQueryStringDotDotSegment', (t) => {
);
});

test('contentWithQueryValueRawPlusSign', (t) => {
// a raw (unencoded) `+` in a query string means a space, by convention
t.is(
urlRewriteFunction(
t.context.currentUrl,
t.context.originalHost,
t.context.originalScheme,
t.context.originalUrl,
t.context.prefix,
'https://www.example.com/javascript/content.txt?query=val+ue',
undefined,
undefined,
undefined,
),
'http://library.kiwix.org/content/myzim_yyyy-mm/www.example.com/javascript/content.txt%3Fquery=val%20ue',
);
});

test('contentWithQueryValueEncodedPlusSign', (t) => {
// a percent-encoded `%2B` in a query string means a literal `+`, and must not be
// confused with a raw `+` (which means a space, see test above). The `+` -> ' '
// substitution must happen on the still-encoded query string, before decoding
// percent-escapes, otherwise this would wrongly turn into a space once
// decodeURIComponent turns `%2B` back into a raw `+`.
t.is(
urlRewriteFunction(
t.context.currentUrl,
t.context.originalHost,
t.context.originalScheme,
t.context.originalUrl,
t.context.prefix,
'https://www.example.com/javascript/content.txt?query=val%2Bue',
undefined,
undefined,
undefined,
),
'http://library.kiwix.org/content/myzim_yyyy-mm/www.example.com/javascript/content.txt%3Fquery=val%2Bue',
);
});

test('contentWithSimplePathWithEqualAndComma', (t) => {
t.is(
urlRewriteFunction(
Expand Down