Skip to content

Commit

Permalink
fix: isUnpackedDir matches non-child directories that have same fol…
Browse files Browse the repository at this point in the history
…der name prefix (#333)

* tmp save

* update test case to test minimatch pattern

* yarn prettier

* remove path separator as it differs on windows

* retrigger build as the timeout is unrelated to edited unit test

* empty commit
  • Loading branch information
mmaietta authored Nov 6, 2024
1 parent 9ec1830 commit 4df48cd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/asar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ function isUnpackedDir(dirPath: string, pattern: string, unpackDirs: string[]) {
}
return true;
} else {
return unpackDirs.some((unpackDir) => dirPath.startsWith(unpackDir));
return unpackDirs.some(
(unpackDir) =>
dirPath.startsWith(unpackDir) && !path.relative(unpackDir, dirPath).startsWith('..'),
);
}
}

Expand Down
9 changes: 7 additions & 2 deletions test/cli-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,18 @@ describe('command line interface', function () {
'test/expected/packthis-unpack-dir.asar',
);
});
it('should create archive from directory with unpacked subdirs and files', async () => {
it('should create archive from directory with unpacked subdirs and files using minimatch', async () => {
await execAsar(
'p test/input/packthis-subdir/ tmp/packthis-unpack-subdir-cli.asar --unpack *.txt --unpack-dir dir2/subdir --exclude-hidden',
'p test/input/packthis-subdir/ tmp/packthis-unpack-subdir-cli.asar --unpack *.txt --unpack-dir "{dir2/subdir,dir2/subdir}" --exclude-hidden',
);
assert.ok(fs.existsSync('tmp/packthis-unpack-subdir-cli.asar.unpacked/file0.txt'));
assert.ok(fs.existsSync('tmp/packthis-unpack-subdir-cli.asar.unpacked/dir1/file1.txt'));
assert.ok(fs.existsSync('tmp/packthis-unpack-subdir-cli.asar.unpacked/dir2/subdir/file2.png'));
assert.ok(fs.existsSync('tmp/packthis-unpack-subdir-cli.asar.unpacked/dir2/subdir/file3.txt'));
assert.ok(
fs.existsSync(
'tmp/packthis-unpack-subdir-cli.asar.unpacked/dir2/subdir-do-not-unpack/file2.png',
) === false,
);
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4df48cd

Please sign in to comment.