From 635b04a5e46f9a8e09d72b6e593b056106706110 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Mon, 23 Jan 2017 18:23:50 +0000 Subject: Strip leading slashes from names when getting zip entries --- test/zipfile.tests.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test') diff --git a/test/zipfile.tests.js b/test/zipfile.tests.js index 52389a8..f6c38d4 100644 --- a/test/zipfile.tests.js +++ b/test/zipfile.tests.js @@ -17,6 +17,30 @@ test('file in zip can be read after being written', function() { }); }); +test('leading slash in path is stripped if set when reading', function() { + var zip = emptyZipFile(); + assert(!zip.exists("/song/title")); + + zip.write("song/title", "Dark Blue"); + + assert(zip.exists("/song/title")); + return zip.read("/song/title", "utf8").then(function(contents) { + assert.equal(contents, "Dark Blue"); + }); +}); + +test('leading slash in path is stripped if set when writing', function() { + var zip = emptyZipFile(); + assert(!zip.exists("song/title")); + + zip.write("/song/title", "Dark Blue"); + + assert(zip.exists("song/title")); + return zip.read("song/title", "utf8").then(function(contents) { + assert.equal(contents, "Dark Blue"); + }); +}); + function emptyZipFile() { var zip = new JSZip(); var buffer = zip.generate({type: "arraybuffer"}); -- cgit v1.2.3