Fix error relocating to filename with different Unicode normalization

This commit is contained in:
Dan Stillman 2017-08-23 11:00:46 +02:00
parent b3043c98ab
commit f4b73d22b8
2 changed files with 29 additions and 1 deletions

View file

@ -2599,7 +2599,17 @@ Zotero.Item.prototype.relinkAttachmentFile = Zotero.Promise.coroutine(function*
// Rename file to filtered name if necessary
if (fileName != newName) {
Zotero.debug("Renaming file '" + fileName + "' to '" + newName + "'");
yield OS.File.move(path, newPath, { noOverwrite: true });
try {
yield OS.File.move(path, newPath, { noOverwrite: true });
}
catch (e) {
if (e instanceof OS.File.Error && e.becauseExists && fileName.normalize() == newName) {
// Ignore normalization differences that the filesystem ignores
}
else {
throw e;
}
}
}
}

View file

@ -916,6 +916,24 @@ describe("Zotero.Item", function () {
assert.isTrue(yield OS.File.exists(tmpFile));
});
it("should handle normalized filenames", function* () {
var item = yield importFileAttachment('test.png');
var path = yield item.getFilePathAsync();
var dir = OS.Path.dirname(path);
var filename = 'tést.pdf'.normalize('NFKD');
// Make sure we're actually testing something -- the test string should be differently
// normalized from what's done in getValidFileName
assert.notEqual(filename, Zotero.File.getValidFileName(filename));
var newPath = OS.Path.join(dir, filename);
yield OS.File.move(path, newPath);
assert.isFalse(yield item.fileExists());
yield item.relinkAttachmentFile(newPath);
assert.isTrue(yield item.fileExists());
});
});