From ab34e9031abcf105cc589214b6ab223bf2ee7600 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 10 Sep 2026 07:22:19 -0400 Subject: [PATCH] Handle overlong filenames in getClosestDirectory() relinkAttachment() calls getClosestDirectory() before showing the file picker, and a too-long filename caused the OS.File.stat() in getClosestDirectory() to throw, which prevented the file picker from appearing after clicking Locate. https://forums.zotero.org/discussion/133685/ --- chrome/content/zotero/xpcom/file.js | 4 +++- test/tests/fileTest.js | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) 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')); });