www

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

commit f4b73d22b832a1eeae32c1873e66318f4aeea882
parent b3043c98ab28c3b1f9fe411cbac1b186ba376be3
Author: Dan Stillman <dstillman@zotero.org>
Date:   Wed, 23 Aug 2017 11:00:46 +0200

Fix error relocating to filename with different Unicode normalization

Diffstat:
Mchrome/content/zotero/xpcom/data/item.js | 12+++++++++++-
Mtest/tests/itemTest.js | 18++++++++++++++++++
2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js @@ -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; + } + } } } diff --git a/test/tests/itemTest.js b/test/tests/itemTest.js @@ -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()); + }); });