Skip to content

Commit

Permalink
Ensure empty subdirectories are always removed
Browse files Browse the repository at this point in the history
  • Loading branch information
GarboMuffin committed Jul 21, 2024
1 parent 68e510a commit 5a8ba9b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/downloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ export const downloadProjectFromBuffer = async (data, options) => {
for (const path of Object.keys(zip.files)) {
if (path.includes('/')) {
zip.remove(path);
needToReZip = true;
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/__snapshots__/sb3.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ exports[`downloads missing assets 1`] = `ArrayBuffer [SHA-256 bbded48ad46f4c1fa9

exports[`downloads missing assets 2`] = `ArrayBuffer [SHA-256 4f25165fae50acf1ae0c05e19e0ecc363e3c93fb263ad84c67b1412ab53e5a4c]`;

exports[`extra empty subdirectory is removed 1`] = `ArrayBuffer [SHA-256 4532296b54eb844a047bf07efa5ff4a21fcff07df64a91a344ca1a7a4a18a8fe]`;

exports[`sb3 project from JSON 1`] = `
{
"arrayBuffer": ArrayBuffer [SHA-256 73f90aff8695ab18da8736f7a0b5054bed29cb2fc08fe59ab34da7d82c6a74d0],
Expand Down
Binary file added test/fixtures/extra-empty-subdirectory.sb3
Binary file not shown.
8 changes: 8 additions & 0 deletions test/sb3.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,11 @@ test('downloads missing assets', async () => {
expect(await zip1.file(path).async('uint8array')).toStrictEqual(await zip2.file(path).async('uint8array'));
}
});

test('extra empty subdirectory is removed', async () => {
const fixtureData = fs.readFileSync(getFixturePath('extra-empty-subdirectory.sb3'));
const project = await SBDL.downloadProjectFromBuffer(fixtureData);
const zip = await JSZip.loadAsync(project.arrayBuffer);
expect(zip.files['empty/']).toBe(undefined);
expect(project.arrayBuffer).toMatchSnapshot();
});

0 comments on commit 5a8ba9b

Please sign in to comment.