1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
var path = require("path");
var fs = require("fs");
var assert = require("assert");
var promises = require("../../lib/promises");
var Files = require("../../lib/docx/files").Files;
var uriToPath = require("../../lib/docx/files").uriToPath;
var testing = require("../testing");
var test = testing.test;
var readFile = promises.promisify(fs.readFile.bind(fs));
describe("Files", function() {
test("can open files with file URI", function() {
var filePath = path.resolve(testing.testPath("tiny-picture.png"));
var files = new Files(null);
return files.read("file:///" + filePath.replace(/^\//, ""), "base64").then(function(contents) {
return readFile(filePath, "base64").then(function(expectedContents) {
assert.deepEqual(contents, expectedContents);
});
});
});
});
describe("uriToPath", function() {
test("leading slash is retained on non-Windows file URIs", function() {
assert.equal(uriToPath("file:///a/b/c"), "/a/b/c");
});
test("URI is unquoted", function() {
assert.equal(uriToPath("file:///a%20b"), "/a b");
});
test("when host is set to localhost then path can be found", function() {
assert.equal(uriToPath("file://localhost/a/b/c"), "/a/b/c");
});
test("when host is set but not localhost then path cannot be found", function() {
assert.throws(function() { uriToPath("file://example/a/b/c"); }, /Could not convert URI to path: file:\/\/example\/a\/b\/c/);
});
});
|