Validate shell openPath targets (#5830)

Co-authored-by: brennanb2025 <brennankbenson@gmail.com>
This commit is contained in:
slashdevcorpse
2026-06-19 17:10:43 -07:00
committed by GitHub
co-authored by brennanb2025
parent 8ef8596ba1
commit 6f6664e744
2 changed files with 43 additions and 2 deletions
+39
View File
@@ -131,6 +131,45 @@ describe('registerShellHandlers', () => {
await expect(handler({})).resolves.toBeNull()
})
describe('shell:openPath', () => {
it('ignores relative paths', async () => {
const handler = getHandler('shell:openPath')
await expect(handler({}, 'relative/workspace')).resolves.toBeUndefined()
expect(statMock).not.toHaveBeenCalled()
expect(showItemInFolderMock).not.toHaveBeenCalled()
})
it('ignores missing paths', async () => {
statMock.mockRejectedValueOnce(new Error('missing'))
const workspacePath = resolve('missing-workspace')
const handler = getHandler('shell:openPath')
await expect(handler({}, workspacePath)).resolves.toBeUndefined()
expect(statMock).toHaveBeenCalledWith(normalize(workspacePath))
expect(showItemInFolderMock).not.toHaveBeenCalled()
})
it('reveals existing absolute paths', async () => {
const workspacePath = resolve('workspace')
const handler = getHandler('shell:openPath')
await expect(handler({}, workspacePath)).resolves.toBeUndefined()
expect(showItemInFolderMock).toHaveBeenCalledWith(normalize(workspacePath))
})
it('swallows launcher failures', async () => {
showItemInFolderMock.mockImplementationOnce(() => {
throw new Error('launcher unavailable')
})
const workspacePath = resolve('workspace')
const handler = getHandler('shell:openPath')
await expect(handler({}, workspacePath)).resolves.toBeUndefined()
expect(showItemInFolderMock).toHaveBeenCalledWith(normalize(workspacePath))
})
})
describe('shell:openInFileManager', () => {
it('rejects relative paths', async () => {
const handler = getHandler('shell:openInFileManager')
+4 -2
View File
@@ -126,8 +126,10 @@ async function openWithSystemDefault(pathValue: string): Promise<boolean> {
}
export function registerShellHandlers(): void {
ipcMain.handle('shell:openPath', (_event, path: string) => {
shell.showItemInFolder(path)
ipcMain.handle('shell:openPath', async (_event, path: string): Promise<void> => {
// Why: keep the legacy fire-and-forget renderer contract while reusing the
// same absolute/existing path validation as the explicit file-manager API.
void (await openInFileManager(path))
})
ipcMain.handle(