Preserve browser URL semantics when unpacking ZIP documents
❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.
Target branch: develop
Observed behavior
getDOMPathsandgetAbsoluteFilePathdecodemedia/clip%252F1.mp4twice, selectingmedia/clip/1.mp4instead ofmedia/clip%2F1.mp4._replaceFilescan substitute a ZIP member for an externalsrcorhrefbecausegetAbsoluteFilePathdiscards the URL origin.replaceDOMPathschanges&to&in HTML<style>text, where browsers do not decode character references._replaceFilesreplaces only the last of two references that resolve to one ZIP member, such asguide.pdfandguide.pdf#p2, because it keys references by resolved path._replaceFilesdrops the#fragmentof a reference it replaces.
Expected behavior
- Resolve local references without interpreting a literal
%2Fin a ZIP member name as a directory separator. - Leave external URLs and HTML stylesheet text intact.
- Replace every reference to a ZIP member, keeping its
#fragment.
User-facing consequences
- A packaged lesson can load the wrong media, replace a remote asset, or break its styles.
- A file a packaged lesson references twice is left unresolved at all but the last reference, and a replaced link loses its fragment target.
Steps to reproduce
- Unpack a document with
<video src="media/clip%252F1.mp4">and both matching ZIP members listed above; inspect which bytes the blob contains. - Unpack
<img src="https://example.org/logo.png">withlogo.pngin the ZIP; inspect the image’ssrc. - Unpack
<style>p::after { content: "A & B" }</style>; reparse the emitted HTML and inspect the style text. - Unpack
<a href="guide.pdf">followed by<a href="guide.pdf#p2">, then the two in the other order, withguide.pdfin the ZIP; inspect bothhrefs.
Context
packages/kolibri-zipondevelop; reproduced with the Jest DOM environment.packages/kolibri-zip/srcis identical onrelease-v0.20.x(9bec30782b), where the repeated-reference and fragment cases were reproduced.
Acceptance Criteria
- [ ] A doubly encoded separator selects the literal
%2Fmember insrc,srcset, and CSS URLs. - [ ] Absolute and protocol-relative external image and stylesheet URLs are not replaced by same-path ZIP members.
- [ ] The unpacked HTML preserves
&inside<style>text. - [ ] Every reference that resolves to one ZIP member is replaced, in either order.
- [ ] A replaced reference keeps its
#fragment. - [ ]
packages/kolibri-zip/test/index.spec.jscovers repeated and fragment references throughZipFile.file().
AI usage
- Codex compared branch output with
developand drafted this report from the parity checks.
Two more sites in ZipFile._replaceFiles, same cause as the external-URL one: each reference is keyed by the path getAbsoluteFilePath resolves it to. For an archive holding guide.pdf, ZipFile.file('index.html') returns these href values:
index.html links, in order |
Returned hrefs |
|---|---|
guide.pdf, https://example.com/guide.pdf |
guide.pdf, blob:… |
guide.pdf, guide.pdf#p2 |
guide.pdf, blob:… |
guide.pdf#p2, guide.pdf |
guide.pdf#p2, blob:… |
- Of two references that resolve to one file, only the last is replaced.
- A replaced reference loses its
#fragment. - The external URL is replaced when it is alone or last, and kept when a local reference to the same path follows it.
- All three reproduce on release-v0.20.x (9bec30782b);
packages/kolibri-zip/srcis identical on develop (758605b764). - H5P, Bloom and QTI read their archives through
ZipFile.
Steps to reproduce
- In
packages/kolibri-zip/test/index.spec.js, serve a zip ofindex.htmlandguide.pdf, withindex.htmlholding one row of links from the table. - Read each
hreffrom(await new ZipFile(url).file('index.html')).toString().
AI usage
Claude Code found this while reviewing the fix for #15970 and ran the rows against release-v0.20.x's kolibri-zip in Jest.
Written by rtibblesbot, an LLM-based coding agent.
Two more reproductions of the decode and <style> cases, through ZipFile.file('index.html'):
src="media/clip%252F1.mp4"with onlymedia/clip/1.mp4in the ZIP: the wrong member is still substituted, so the fix must leave the reference unresolved, not fall back.<style>p { background-image: url("a.png?x=1&y=2") }</style>witha.pngabsent: the emitted query string becomes?x=1&y=2, so a CSS URL loses its parameters.
Written by rtibblesbot, an LLM-based coding agent.