fix: open Windows OSC file path links (#4034)

This commit is contained in:
Neil
2026-05-31 01:58:48 -07:00
committed by GitHub
parent f9231ccd5d
commit 39be32da76
2 changed files with 55 additions and 9 deletions
@@ -371,6 +371,36 @@ describe('handleOscLink', () => {
expect(openFilePathMock).not.toHaveBeenCalled()
})
it('opens Windows absolute OSC link targets that parse as URL schemes', async () => {
setPlatform('Windows')
handleOscLink(
'C:\\repo\\src\\index.ts:12:3',
{ metaKey: false, ctrlKey: true },
{
...deps,
startupCwd: 'C:\\repo',
worktreePath: 'C:\\repo'
}
)
await flushAsyncWork()
await flushDoubleRaf()
expect(authorizeExternalPathMock).toHaveBeenCalledWith({
targetPath: 'C:/repo/src/index.ts'
})
expect(openFileMock).toHaveBeenCalledWith(
expect.objectContaining({ filePath: 'C:/repo/src/index.ts' })
)
expect(setPendingEditorRevealMock).toHaveBeenNthCalledWith(1, null)
expect(setPendingEditorRevealMock).toHaveBeenNthCalledWith(2, {
filePath: 'C:/repo/src/index.ts',
line: 12,
column: 3,
matchLength: 0
})
})
it('opens Windows UNC file URL links from Windows worktrees', async () => {
setPlatform('Windows')
@@ -30,21 +30,37 @@ export function handleOscLink(
// without holding a button) extends a selection until the next click/Esc.
event?.preventDefault?.()
let parsed: URL
try {
parsed = new URL(rawText)
} catch {
const openDetectedPathLink = (): boolean => {
const resolved = resolveTerminalFileLinkText(
rawText,
deps.startupCwd || deps.worktreePath,
deps.terminalHomePath
)
if (resolved) {
openDetectedFilePath(resolved.absolutePath, resolved.line, resolved.column, {
...deps,
openWithSystemDefault: Boolean(event?.shiftKey)
})
if (!resolved) {
return false
}
openDetectedFilePath(resolved.absolutePath, resolved.line, resolved.column, {
...deps,
openWithSystemDefault: Boolean(event?.shiftKey)
})
return true
}
if (
isWindowsAbsolutePathLike(rawText) &&
isWindowsAbsolutePathLike(deps.startupCwd || deps.worktreePath) &&
openDetectedPathLink()
) {
// Why: `new URL("C:\\path\\file.ts")` succeeds with protocol `c:`;
// Windows OSC links need file-path routing before generic URL parsing.
return
}
let parsed: URL
try {
parsed = new URL(rawText)
} catch {
openDetectedPathLink()
return
}