From e1576704b698bee8f263070a9c9a1d5aaebe1488 Mon Sep 17 00:00:00 2001 From: 5saviahv <5saviahv@users.noreply.github.com> Date: Fri, 7 Jun 2024 21:28:47 +0300 Subject: [PATCH 1/2] addFile backslash test --- adm-zip.js | 3 ++- test/mocha.js | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/adm-zip.js b/adm-zip.js index 33316f6..51e37d7 100644 --- a/adm-zip.js +++ b/adm-zip.js @@ -423,13 +423,14 @@ module.exports = function (/**String*/ input, /** object */ options) { * @param {number | object} attr - number as unix file permissions, object as filesystem Stats object */ addFile: function (/**String*/ entryName, /**Buffer*/ content, /**String*/ comment, /**Number*/ attr) { + entryName = Utils.canonical(entryName); let entry = getEntry(entryName); const update = entry != null; // prepare new entry if (!update) { entry = new ZipEntry(); - entry.entryName = Utils.canonical(entryName); + entry.entryName = entryName; } entry.comment = comment || ""; diff --git a/test/mocha.js b/test/mocha.js index cbc481f..9b816b1 100644 --- a/test/mocha.js +++ b/test/mocha.js @@ -255,6 +255,26 @@ describe("adm-zip", () => { expect(zip2Entries).to.deep.equal(["c.txt", "b.txt", "a.txt"]); }); + it("windows style path with backslash should be converted to slashes", () => { + const content = "test"; + const comment = "comment"; + + // is sorting working - value "false" + const zip1 = new Zip({ noSort: true }); + // next 3 lines are with identical names, so only one file is added + zip1.addFile("..\\..\\..\\windows\\system32\\drivers\\etc\\hosts.txt", content, comment); + zip1.addFile("aa\\bb\\..\\cc\\..\\..\\windows\\system32\\drivers\\admin\\..\\etc\\hosts.txt", content, comment); + zip1.addFile(".\\windows\\system32\\drivers\\etc\\hosts.txt", content, comment); + // 3 other file + zip1.addFile("system32\\drivers\\etc\\hosts.txt", content, comment); + zip1.addFile("drivers\\etc\\hosts.txt", content, comment); + zip1.addFile(".\\hosts.txt", content, comment); + zip1.toBuffer(); + + const zip1Entries = zip1.getEntries().map((e) => e.entryName); + expect(zip1Entries).to.deep.equal(["windows/system32/drivers/etc/hosts.txt", "system32/drivers/etc/hosts.txt", "drivers/etc/hosts.txt", "hosts.txt"]); + }); + /* it("repro: symlink", () => { const zip = new Zip("./test/assets/symlink.zip"); From e4ced4f52396bb2b4f9c29830a710f888f47b189 Mon Sep 17 00:00:00 2001 From: 5saviahv <5saviahv@users.noreply.github.com> Date: Fri, 7 Jun 2024 21:30:03 +0300 Subject: [PATCH 2/2] format --- test/large_directory_size/large_directory_size.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/large_directory_size/large_directory_size.test.js b/test/large_directory_size/large_directory_size.test.js index 571659d..1d896e2 100644 --- a/test/large_directory_size/large_directory_size.test.js +++ b/test/large_directory_size/large_directory_size.test.js @@ -14,4 +14,3 @@ describe("read zip file header with invalid large number of entries", () => { }, new Error("Number of disk entries is too large")); }); }); -