Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Open packages wrapped in a folder or nested in a ZIP, as eXeLearning does (#45) - #51

Merged
erseco merged 2 commits into
mainfrom
feat/issue-45-wrapped-nested
Dec 2, 2026
Merged

erseco merged 2 commits into
mainfrom
feat/issue-45-wrapped-nested

Conversation

@erseco

@erseco erseco commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Closes #45

Problem

eXeLearning's importer opens two shapes that elp-parser refused with Invalid ELP file: No content XML found.: a ZIP whose entries all live under one folder (GitHub's "Download ZIP", a folder compressed with macOS Finder), and a ZIP whose only package is one .elp/.elpx at its root.

Fix

ArchiveReader finds the package the way upstream does, only when there is no content.xml or contentv3.xml at the root:

  • Wrapped: if every entry lives under one top-level folder, that folder is stripped from every name. __MACOSX/ and ._* entries are ignored, both when deciding and when listing or extracting.
  • Nested: if the ZIP holds exactly one .elp/.elpx at its root, it is copied to a temporary file through extractEntry(), so under the same size limits and safety checks, and read in its place. This goes one level down at most (the inner package may itself be wrapped). The temporary file is removed when the reader goes away.
  • More than one nested package: UnsupportedFormatException ("The ZIP holds more than one eXeLearning package: extract the one to open.").

Everything goes through the reader, so ELPParser::fromFile(), fromStream(), fromContents(), inspect(), entry reads and streaming, extract() and the archive hash all see the package itself. A regular package is not touched.

Tests

  • New tests/Unit/WrappedNestedPackageTest.php: wrapped (with __MACOSX entries), nested, nested-and-wrapped, fromContents(), inspect(), extract() without the folder, several packages refused, two levels refused, size limits still applied, and a regular package left alone. Three of its four tests failed before the change.
  • tests/Unit/CorpusTest.php: the two corpus packages (edge/wrapped-in-folder, edge/nested-package) now open and match the expected pages and unused resources, and the "not opened yet" list is gone. With ELPX_TEST_CORPUS set: 4 passed (262 assertions).
  • composer test: 99 passed (4 corpus tests skipped without the variable). composer lint and composer analyse clean.
  • CHANGELOG.md (Unreleased → Added) and docs/formats.md describe it.

Left out

  • The source extension used for format heuristics stays the outer file's (.zip for a nested package), so getPackageProfile() reports ode-… rather than elpx-… for one.

…does

ArchiveReader now finds the package the way eXeLearning's importer does. When
there is no content.xml or contentv3.xml at the root, a single top-level folder
is stripped from every name (macOS __MACOSX/ and ._* entries are ignored), and
a ZIP whose only package is one .elp/.elpx at its root is copied out under the
same limits and safety checks and read in its place, one level down at most.
ELPParser, inspect(), the stream and contents constructors and extract() all go
through it. More than one nested package is refused with a message that says so.

Closes #45
@erseco erseco added the enhancement New feature or request label Dec 1, 2026
@erseco erseco self-assigned this Dec 1, 2026
@codecov-commenter

codecov-commenter commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.61905% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.8%. Comparing base (c0694c9) to head (f5c972c).

Files with missing lines Patch % Lines
src/Archive/ArchiveReader.php 97.5% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##              main     #51     +/-   ##
=========================================
+ Coverage     92.6%   92.8%   +0.1%     
- Complexity     834     861     +27     
=========================================
  Files           29      29             
  Lines         2698    2767     +69     
=========================================
+ Hits          2500    2568     +68     
- Misses         198     199      +1     
Flag Coverage Δ
unit 92.8% <97.6%> (+0.1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/ELPParser.php 96.1% <100.0%> (+<0.1%) ⬆️
src/Support/ProjectInspector.php 95.8% <100.0%> (+0.8%) ⬆️
src/Archive/ArchiveReader.php 82.1% <97.5%> (+3.8%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@erseco
erseco merged commit ef3511c into main Dec 2, 2026
21 checks passed
@erseco
erseco deleted the feat/issue-45-wrapped-nested branch December 2, 2026 04:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Open packages wrapped in a folder or nested in a ZIP, as eXeLearning does

2 participants