From f2440eb826d103f50a62ee8b8152f34a1328b524 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 13 Jan 2017 06:48:02 -0500 Subject: [PATCH] Fix passing file: URI to Zotero.File.getContentsAsync() --- chrome/content/zotero/xpcom/file.js | 2 +- test/tests/fileTest.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/file.js b/chrome/content/zotero/xpcom/file.js index c9af26f25..d03885d1d 100644 --- a/chrome/content/zotero/xpcom/file.js +++ b/chrome/content/zotero/xpcom/file.js @@ -273,7 +273,7 @@ Zotero.File = new function(){ if (source instanceof Components.interfaces.nsIFile) { source = source.path; } - else if (source.startsWith('^file:')) { + else if (source.startsWith('file:')) { source = OS.Path.fromFileURI(source); } var options = { diff --git a/test/tests/fileTest.js b/test/tests/fileTest.js index 7236387a2..d8c2cc99c 100644 --- a/test/tests/fileTest.js +++ b/test/tests/fileTest.js @@ -48,6 +48,13 @@ describe("Zotero.File", function () { assert.lengthOf(contents, 6); assert.equal(contents, "Zotero"); }); + + it("should get a file from a file: URI", function* () { + var contents = yield Zotero.File.getContentsAsync( + OS.Path.toFileURI(OS.Path.join(getTestDataDirectory().path, "test.txt")) + ); + assert.isTrue(contents.startsWith('Zotero')); + }); }) describe("#getBinaryContentsAsync()", function () {