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).
This commit is contained in:
Dan Stillman 2017-08-18 16:04:22 +02:00
parent acb990c75d
commit 7386b376f3
2 changed files with 15 additions and 8 deletions

View file

@ -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;

View file

@ -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");