kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Preserve browser URL semantics when unpacking ZIP documents

Open rtibblesbot opened this issue 1 week ago • 2 comments

❌ 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

  • getDOMPaths and getAbsoluteFilePath decode media/clip%252F1.mp4 twice, selecting media/clip/1.mp4 instead of media/clip%2F1.mp4.
  • _replaceFiles can substitute a ZIP member for an external src or href because getAbsoluteFilePath discards the URL origin.
  • replaceDOMPaths changes & to &amp; in HTML <style> text, where browsers do not decode character references.
  • _replaceFiles replaces only the last of two references that resolve to one ZIP member, such as guide.pdf and guide.pdf#p2, because it keys references by resolved path.
  • _replaceFiles drops the #fragment of a reference it replaces.

Expected behavior

  • Resolve local references without interpreting a literal %2F in 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"> with logo.png in the ZIP; inspect the image’s src.
  • 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, with guide.pdf in the ZIP; inspect both hrefs.

Context

  • packages/kolibri-zip on develop; reproduced with the Jest DOM environment.
  • packages/kolibri-zip/src is identical on release-v0.20.x (9bec30782b), where the repeated-reference and fragment cases were reproduced.

Acceptance Criteria

  • [ ] A doubly encoded separator selects the literal %2F member in src, 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.js covers repeated and fragment references through ZipFile.file().

AI usage

  • Codex compared branch output with develop and drafted this report from the parity checks.

rtibblesbot avatar Nov 24 '26 12:11 rtibblesbot

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/src is identical on develop (758605b764).
  • H5P, Bloom and QTI read their archives through ZipFile.

Steps to reproduce

  1. In packages/kolibri-zip/test/index.spec.js, serve a zip of index.html and guide.pdf, with index.html holding one row of links from the table.
  2. Read each href from (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.

rtibblesbot avatar Nov 25 '26 08:11 rtibblesbot

Two more reproductions of the decode and <style> cases, through ZipFile.file('index.html'):

  • src="media/clip%252F1.mp4" with only media/clip/1.mp4 in 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> with a.png absent: the emitted query string becomes ?x=1&amp;y=2, so a CSS URL loses its parameters.

Written by rtibblesbot, an LLM-based coding agent.

rtibblesbot avatar Nov 27 '26 09:11 rtibblesbot