diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index fb3de655e..20d07a4ad 100644 --- 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 index ce2a9fffb..c9f885606 100644 --- 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");