From 9c37fa86d1410bb917dd5f5da4dbc013918633e5 Mon Sep 17 00:00:00 2001 From: 5saviahv <5saviahv@users.noreply.github.com> Date: Sat, 1 Jun 2024 12:15:12 +0300 Subject: [PATCH 1/2] minor fixes found from issues --- adm-zip.js | 4 +++- package.json | 2 +- zipEntry.js | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/adm-zip.js b/adm-zip.js index f38797d..33316f6 100644 --- a/adm-zip.js +++ b/adm-zip.js @@ -429,7 +429,7 @@ module.exports = function (/**String*/ input, /** object */ options) { // prepare new entry if (!update) { entry = new ZipEntry(); - entry.entryName = entryName; + entry.entryName = Utils.canonical(entryName); } entry.comment = comment || ""; @@ -464,6 +464,8 @@ module.exports = function (/**String*/ input, /** object */ options) { entry.setData(content); if (!update) _zip.setEntry(entry); + + return entry; }, /** diff --git a/package.json b/package.json index 8263801..54f8d2d 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "url": "https://github.com/cthackers/adm-zip.git" }, "engines": { - "node": ">=6.0" + "node": ">=12.0" }, "devDependencies": { "chai": "^4.3.4", diff --git a/zipEntry.js b/zipEntry.js index 9deed1f..486e092 100644 --- a/zipEntry.js +++ b/zipEntry.js @@ -12,7 +12,8 @@ module.exports = function (/*Buffer*/ input) { _extra = Buffer.alloc(0); function getCompressedDataFromZip() { - if (!input || !Buffer.isBuffer(input)) { + //if (!input || !Buffer.isBuffer(input)) { + if (!input || !(input instanceof Uint8Array)) { return Buffer.alloc(0); } _centralHeader.loadLocalHeaderFromBinary(input); From 3fbc83ca6b299c68b36d467bc5536163c863eb93 Mon Sep 17 00:00:00 2001 From: 5saviahv <5saviahv@users.noreply.github.com> Date: Sat, 1 Jun 2024 13:01:29 +0300 Subject: [PATCH 2/2] added test for 438 --- test/mocha.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/mocha.js b/test/mocha.js index 2689766..cbc481f 100644 --- a/test/mocha.js +++ b/test/mocha.js @@ -218,6 +218,16 @@ describe("adm-zip", () => { fs.unlinkSync("./text.txt"); }); + it("passes issue-438-AddFile with windows path sepator", () => { + const zip = new Zip(); + zip.addFile("foo\\bar.txt", "test", "test"); + zip.extractAllTo(destination); + + const files = walk(destination); + + expect(files.sort()).to.deep.equal([pth.normalize("./test/xxx/foo/bar.txt")].sort()); + }); + it("testing noSort option", () => { const content = "test"; const comment = "comment";