From e81f83906d26ace7c38b0b7b24e0d5f98da35172 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Mon, 23 Jan 2017 20:23:03 +0000 Subject: Handle base-relative URIs entirely in entry name generation --- lib/zipfile.js | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'lib/zipfile.js') diff --git a/lib/zipfile.js b/lib/zipfile.js index efe519c..9542ae1 100644 --- a/lib/zipfile.js +++ b/lib/zipfile.js @@ -3,16 +3,16 @@ var JSZip = require("jszip"); var promises = require("./promises"); exports.openArrayBuffer = openArrayBuffer; -exports.joinZipPath = joinZipPath; +exports.uriToZipEntryName = uriToZipEntryName; function openArrayBuffer(arrayBuffer) { var zipFile = new JSZip(arrayBuffer); function exists(name) { - return zipFile.file(normaliseName(name)) !== null; + return zipFile.file(name) !== null; } function read(name, encoding) { - var array = zipFile.file(normaliseName(name)).asUint8Array(); + var array = zipFile.file(name).asUint8Array(); var buffer = new Buffer(array); if (encoding) { return promises.when(buffer.toString(encoding)); @@ -22,7 +22,7 @@ function openArrayBuffer(arrayBuffer) { } function write(name, contents) { - zipFile.file(normaliseName(name), contents); + zipFile.file(name, contents); } function toBuffer() { @@ -37,20 +37,12 @@ function openArrayBuffer(arrayBuffer) { }; } -function normaliseName(name) { - if (name.charAt(0) === "/") { - return name.substr(1); - } else { - return name; - } -} - -function joinZipPath(first, second) { - if (second.charAt(0) === "/") { - return second; +function uriToZipEntryName(base, uri) { + if (uri.charAt(0) === "/") { + return uri.substr(1); } else { // In general, we should check first and second for trailing and leading slashes, // but in our specific case this seems to be sufficient - return first + "/" + second; + return base + "/" + uri; } } -- cgit v1.2.3