aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2017-01-23 20:42:02 +0000
committerMichael Williamson <mike@zwobble.org>2017-01-23 20:42:02 +0000
commit15f4381cf54901895836551a30f66c0cee974a0c (patch)
tree6a02b9c3d7be8adbc5315b7eaa29eb217a9d1418
parente81f83906d26ace7c38b0b7b24e0d5f98da35172 (diff)
Move target URI handling out of zipfile module
-rw-r--r--lib/docx/body-reader.js2
-rw-r--r--lib/docx/uris.js11
-rw-r--r--lib/zipfile.js11
-rw-r--r--test/docx/uris.tests.js22
-rw-r--r--test/zipfile.tests.js18
5 files changed, 35 insertions, 29 deletions
diff --git a/lib/docx/body-reader.js b/lib/docx/body-reader.js
index e683168..529d6f2 100644
--- a/lib/docx/body-reader.js
+++ b/lib/docx/body-reader.js
@@ -5,7 +5,7 @@ var _ = require("underscore");
var documents = require("../documents");
var Result = require("../results").Result;
var warning = require("../results").warning;
-var uriToZipEntryName = require("../zipfile").uriToZipEntryName;
+var uriToZipEntryName = require("./uris").uriToZipEntryName;
function BodyReader(options) {
diff --git a/lib/docx/uris.js b/lib/docx/uris.js
new file mode 100644
index 0000000..0179e5b
--- /dev/null
+++ b/lib/docx/uris.js
@@ -0,0 +1,11 @@
+exports.uriToZipEntryName = uriToZipEntryName;
+
+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 base + "/" + uri;
+ }
+}
diff --git a/lib/zipfile.js b/lib/zipfile.js
index 9542ae1..7c534c7 100644
--- a/lib/zipfile.js
+++ b/lib/zipfile.js
@@ -3,7 +3,6 @@ var JSZip = require("jszip");
var promises = require("./promises");
exports.openArrayBuffer = openArrayBuffer;
-exports.uriToZipEntryName = uriToZipEntryName;
function openArrayBuffer(arrayBuffer) {
var zipFile = new JSZip(arrayBuffer);
@@ -36,13 +35,3 @@ function openArrayBuffer(arrayBuffer) {
toBuffer: toBuffer
};
}
-
-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 base + "/" + uri;
- }
-}
diff --git a/test/docx/uris.tests.js b/test/docx/uris.tests.js
new file mode 100644
index 0000000..5b2afab
--- /dev/null
+++ b/test/docx/uris.tests.js
@@ -0,0 +1,22 @@
+var assert = require("assert");
+
+var zipfile = require("../../lib/docx/uris");
+var test = require("../test")(module);
+
+
+test("uriToZipEntryName", {
+ "when path does not have leading slash then path is resolved relative to base": function() {
+ assert.equal(
+ zipfile.uriToZipEntryName("one/two", "three/four"),
+ "one/two/three/four"
+ )
+ },
+
+ "when path has leading slash then base is ignored": function() {
+ assert.equal(
+ zipfile.uriToZipEntryName("one/two", "/three/four"),
+ "three/four"
+ )
+ }
+});
+
diff --git a/test/zipfile.tests.js b/test/zipfile.tests.js
index 8c2f6c1..56c7f9b 100644
--- a/test/zipfile.tests.js
+++ b/test/zipfile.tests.js
@@ -2,8 +2,8 @@ var assert = require("assert");
var JSZip = require("jszip");
-var test = require("./test")(module);
var zipfile = require("../lib/zipfile");
+var test = require("./test")(module);
test('file in zip can be read after being written', function() {
var zip = emptyZipFile();
@@ -22,19 +22,3 @@ function emptyZipFile() {
var buffer = zip.generate({type: "arraybuffer"});
return zipfile.openArrayBuffer(buffer);
}
-
-test("uriToZipEntryName", {
- "when path does not have leading slash then path is resolved relative to base": function() {
- assert.equal(
- zipfile.uriToZipEntryName("one/two", "three/four"),
- "one/two/three/four"
- )
- },
-
- "when path has leading slash then base is ignored": function() {
- assert.equal(
- zipfile.uriToZipEntryName("one/two", "/three/four"),
- "three/four"
- )
- }
-});