Skip to content

Commit 009ee26

Browse files
authored
Merge pull request #403 from robincodex/master
Fix parameter initialization bug of extractAllToAsync
2 parents c334423 + 28e460f commit 009ee26

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

adm-zip.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -634,12 +634,14 @@ module.exports = function (/**String*/ input, /** object */ options) {
634634
* @param callback The callback will be executed when all entries are extracted successfully or any error is thrown.
635635
*/
636636
extractAllToAsync: function (/**String*/ targetPath, /**Boolean*/ overwrite, /**Boolean*/ keepOriginalPermission, /**Function*/ callback) {
637-
if (!callback) {
638-
callback = function () {};
639-
}
640637
overwrite = get_Bool(overwrite, false);
641638
if (typeof keepOriginalPermission === "function" && !callback) callback = keepOriginalPermission;
642639
keepOriginalPermission = get_Bool(keepOriginalPermission, false);
640+
if (!callback) {
641+
callback = function (err) {
642+
throw new Error(err);
643+
};
644+
}
643645
if (!_zip) {
644646
callback(new Error(Utils.Errors.NO_ZIP));
645647
return;

test/mocha.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe("adm-zip", () => {
2828
);
2929
});
3030

31-
it("zip.extractAllToAsync()", (done) => {
31+
it("zip.extractAllToAsync(destination, false, false, callback)", (done) => {
3232
const zip = new Zip("./test/assets/ultra.zip");
3333
zip.extractAllToAsync(destination, false, false, (error) => {
3434
const files = walk(destination);
@@ -45,6 +45,24 @@ describe("adm-zip", () => {
4545
done();
4646
});
4747
});
48+
49+
it("zip.extractAllToAsync(destination, false, callback)", (done) => {
50+
const zip = new Zip("./test/assets/ultra.zip");
51+
zip.extractAllToAsync(destination, false, (error) => {
52+
const files = walk(destination);
53+
expect(files.sort()).to.deep.equal(
54+
[
55+
pth.normalize("./test/xxx/attributes_test/asd/New Text Document.txt"),
56+
pth.normalize("./test/xxx/attributes_test/blank file.txt"),
57+
pth.normalize("./test/xxx/attributes_test/New folder/hidden.txt"),
58+
pth.normalize("./test/xxx/attributes_test/New folder/hidden_readonly.txt"),
59+
pth.normalize("./test/xxx/attributes_test/New folder/readonly.txt"),
60+
pth.normalize("./test/xxx/utes_test/New folder/somefile.txt")
61+
].sort()
62+
);
63+
done();
64+
});
65+
});
4866

4967
it("zip pathTraversal", () => {
5068
const target = pth.join(destination, "test");

0 commit comments

Comments
 (0)