Skip to content

Commit

Permalink
addFile backslash test
Browse files Browse the repository at this point in the history
  • Loading branch information
5saviahv committed Jun 7, 2024
1 parent 28fdcdf commit e157670
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion adm-zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || "";

Expand Down
20 changes: 20 additions & 0 deletions test/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit e157670

Please sign in to comment.