diff --git a/chrome/content/zotero/xpcom/file.js b/chrome/content/zotero/xpcom/file.js index b9e20f0df2..41d7709138 100644 --- a/chrome/content/zotero/xpcom/file.js +++ b/chrome/content/zotero/xpcom/file.js @@ -102,7 +102,9 @@ Zotero.File = new function () { } } catch (e) { - if (e.becauseNoSuchFile) {} + // A missing file, or a filename too long for the filesystem, might still have + // an existing parent directory, so continue below + if (e.becauseNoSuchFile || e.message?.includes('NS_ERROR_FILE_NAME_TOO_LONG')) {} // A path that can't be parsed (e.g., a POSIX-style path on Windows) doesn't // exist either else if (e.message?.includes('NS_ERROR_FILE_UNRECOGNIZED_PATH')) { diff --git a/test/tests/fileTest.js b/test/tests/fileTest.js index 229ad8bace..c7412b288a 100644 --- a/test/tests/fileTest.js +++ b/test/tests/fileTest.js @@ -199,6 +199,14 @@ describe("Zotero.File", function () { assert.equal(closest, tmpDir); }); + it("should return parent directory for a filename too long for the filesystem", async function () { + var tmpDir = await getTempDirectory(); + var closest = await Zotero.File.getClosestDirectory( + OS.Path.join(tmpDir, 'a'.repeat(1000) + '.pdf') + ); + assert.equal(closest, tmpDir); + }); + it("should return false for a path that doesn't exist at all", async function () { assert.isFalse(await Zotero.File.getClosestDirectory('/a/b/c')); });