mirror of
https://github.com/zotero/zotero.git
synced 2026-09-14 23:21:03 +00:00
Handle overlong filenames in getClosestDirectory()
Some checks are pending
Some checks are pending
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/
(cherry picked from commit ab34e9031a)
This commit is contained in:
parent
33af51c7a1
commit
2b36770f40
2 changed files with 11 additions and 1 deletions
|
|
@ -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')) {
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue