Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions test/archiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down