www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 7386b376f361b4e7fe4283b40f12c3368b8b8123
parent acb990c75da2d4bca096401902cce22c5a0ac3f4
Author: Dan Stillman <dstillman@zotero.org>
Date:   Fri, 18 Aug 2017 16:04:22 +0200

Fix linked attachment base directory handling at drive root

The first letter of the relative path was being removed on save if the
base directory was set to the drive root (e.g. D:\ instead of D:\foo).

Diffstat:
Mchrome/content/zotero/xpcom/attachments.js | 17+++++++++--------
Mtest/tests/attachmentsTest.js | 6++++++
2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js @@ -882,14 +882,15 @@ Zotero.Attachments = new function(){ } if (Zotero.File.directoryContains(basePath, path)) { - basePath = OS.Path.normalize(basePath); - path = OS.Path.normalize(path); - path = this.BASE_PATH_PLACEHOLDER - + path.substr(basePath.length + 1) - // Since stored paths can be synced to other platforms, use - // forward slashes for consistency. resolveRelativePath() will - // convert to the appropriate platform-specific slash on use. - .replace(/\\/g, "/"); + // Since stored paths can be synced to other platforms, use forward slashes for consistency. + // resolveRelativePath() will convert to the appropriate platform-specific slash on use. + basePath = OS.Path.normalize(basePath).replace(/\\/g, "/"); + path = OS.Path.normalize(path).replace(/\\/g, "/"); + // Normalize D:\ vs. D:\foo + if (!basePath.endsWith('/')) { + basePath += '/'; + } + path = this.BASE_PATH_PLACEHOLDER + path.substr(basePath.length) } return path; diff --git a/test/tests/attachmentsTest.js b/test/tests/attachmentsTest.js @@ -210,6 +210,12 @@ describe("Zotero.Attachments", function() { }); describe("#getBaseDirectoryRelativePath()", function () { + it("should handle base directory at Windows drive root", function () { + Zotero.Prefs.set('baseAttachmentPath', "C:\\"); + var path = Zotero.Attachments.getBaseDirectoryRelativePath("C:\\file.txt"); + assert.equal(path, Zotero.Attachments.BASE_PATH_PLACEHOLDER + "file.txt"); + }); + it("should convert backslashes to forward slashes", function () { Zotero.Prefs.set('baseAttachmentPath', "C:\\foo\\bar"); var path = Zotero.Attachments.getBaseDirectoryRelativePath("C:\\foo\\bar\\test\\file.txt");