diff --git a/lib/utils.js b/lib/utils.js index b8e7e1802..998f23a09 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -56,9 +56,15 @@ export function normalizeInputSource(source) { } export function sanitizePath(filepath) { - return normalizePath(filepath, false) + var sanitized = normalizePath(filepath, false) .replace(/^\w+:/, "") .replace(/^(\.\.\/|\/)+/, ""); + + if (sanitized.length === 0 && filepath.length > 0) { + return filepath; + } + + return sanitized; } export function trailingSlashIt(str) { diff --git a/test/archiver.js b/test/archiver.js index 20de9ad19..eb5bed59c 100644 --- a/test/archiver.js +++ b/test/archiver.js @@ -189,6 +189,18 @@ describe("archiver", function () { assert.propertyVal(entries["directory/"], "crc32", 0); assert.propertyVal(entries["directory/"], "size", 0); }); + it("should allow appending an entry named '\\'", function (done) { + var archive = new JsonArchive(); + var stream = new WriteStream("tmp/append-backslash.json"); + stream.on("close", function () { + var res = readJSON("tmp/append-backslash.json"); + assert.equal(res[0].name, "\\"); + assert.equal(res[0].type, "file"); + done(); + }); + archive.pipe(stream); + archive.append("test content", { name: "\\" }).finalize(); + }); }); describe("#directory", function () { var actual;