From bd46b03ee8e6055a5c53a3de2b4f8d675135124e Mon Sep 17 00:00:00 2001 From: ANIRUDDHA ADAK Date: Mon, 7 Sep 2026 08:40:10 +0530 Subject: [PATCH] fix(electron-utils): skip drop files whose path resolution throws (#240) * fix(electron-utils): skip drop files whose path resolution throws * fix(electron-utils): extract throwing-resolver guard to satisfy lint --------- Co-authored-by: Aniruddha Adak --- packages/electron-utils/src/drop-open.ts | 15 +++++++++++++-- packages/electron-utils/tests/drop-open.test.ts | 8 ++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/electron-utils/src/drop-open.ts b/packages/electron-utils/src/drop-open.ts index 5fb18a7..e50793b 100644 --- a/packages/electron-utils/src/drop-open.ts +++ b/packages/electron-utils/src/drop-open.ts @@ -29,6 +29,15 @@ const MAX_DROPPED_FILES = 20 /** the resolver signature webUtils.getPathForFile satisfies; injectable for tests */ type PathResolver = (file: File) => string +/** Resolve one dropped file, tolerating resolver failures (see droppableFilePaths). */ +function tryResolvePath(file: File, getPathForFile: PathResolver): string { + try { + return getPathForFile(file).trim() + } catch { + return '' + } +} + /** * Resolve an event's dropped files to local paths. Returns null when the drag * carries no OS files at all (internal text/element drags), or [] when it does @@ -42,8 +51,10 @@ export function droppableFilePaths( if (!transfer || !transfer.types.includes('Files')) return null const paths: string[] = [] for (const file of Array.from(transfer.files)) { - // non-empty guard covers virtual entries (e.g. page-referenced blobs) that resolve to '' - const path = getPathForFile(file).trim() + // A throwing resolver (e.g. a sandboxed entry Electron cannot map) must + // not abort the whole drop: skip that file like a virtual entry. + // Non-empty guard covers virtual entries (e.g. page-referenced blobs). + const path = tryResolvePath(file, getPathForFile) if (path) paths.push(path) } return paths diff --git a/packages/electron-utils/tests/drop-open.test.ts b/packages/electron-utils/tests/drop-open.test.ts index d51a1bc..3cde6e8 100644 --- a/packages/electron-utils/tests/drop-open.test.ts +++ b/packages/electron-utils/tests/drop-open.test.ts @@ -101,6 +101,14 @@ describe('droppableFilePaths', () => { ) expect(result).toEqual(['/tmp/doc.docx']) }) + + it('skips files whose path resolution throws instead of aborting the drop', () => { + const result = droppableFilePaths(fileDrag(['bad.docx', 'good.docx']) as never, (file) => { + if ((file as { name: string }).name === 'bad.docx') throw new Error('denied') + return '/tmp/good.docx' + }) + expect(result).toEqual(['/tmp/good.docx']) + }) }) describe('partitionDropPayload', () => {