Skip to content

fix(cli): handle Windows drive letters in path URL validation - #282

Merged
dirac-run merged 1 commit into
dirac-run:masterfrom
Tyagiquamar:fix/121-windows-path-url-scheme
Nov 22, 2026
Merged

dirac-run merged 1 commit into
dirac-run:masterfrom
Tyagiquamar:fix/121-windows-path-url-scheme

Conversation

@Tyagiquamar

Copy link
Copy Markdown
Contributor

Summary

Fixes an issue where Windows paths with drive letters (such as C:\... or D:\...) passed to openExternal were parsed as URLs with single-letter drive protocols (for example c:), causing openExternal to throw an unhandled exception: Blocked URL with disallowed scheme 'c:'. This prevented CLI diagnostic utilities like dirac dev log from opening logs and caused unhandled rejection failures on Windows environments.

Fixes #121

Root Cause & Problem

In src/utils/env.ts, openExternal validated target URLs by passing the target string directly to new URL(url) and enforcing ALLOWED_OPEN_SCHEMES = ["https:", "http:"].
When Windows file paths or commands like dirac dev log called openExternal(getCliLogFilePath()):

  1. Node's WHATWG URL parser treated the Windows drive letter C: as a scheme protocol (parsed.protocol === "c:").
  2. Because "c:" was not in ALLOWED_OPEN_SCHEMES, openExternal threw Error: Blocked URL with disallowed scheme 'c:'.
  3. In CLI mode, unhandled promise rejections are routed through onUnhandledException, disrupting normal event loop and input stream processing until user interaction occurs. On POSIX, raw file paths would also fail with TypeError: Invalid URL.

Technical Solution

  1. In src/utils/env.ts:
    • Added "file:" to ALLOWED_OPEN_SCHEMES.
    • Introduced normalizeOpenTarget(target: string): string to detect Windows drive paths (C:\..., d:/...), UNC paths (\\...), and absolute filesystem paths, normalizing them to valid file:// URLs using pathToFileURL(target).href.
    • Preserved strict validation against disallowed schemes (e.g. javascript:, data:) and invalid URL strings.
    • Handled both remote HTTP(S) links and local file/log targets cleanly across Windows and POSIX.
  2. In cli/src/utils/openExternal.test.ts:
    • Added unit test coverage for Windows drive paths (C:\...), forward-slash Windows paths (d:/...), direct file:// URLs, disallowed scheme rejections (javascript:, data:), and invalid URLs.

Test Plan

  • Ran targeted vitest suites:
    • npx vitest run src/utils/openExternal.test.ts (13 tests passed)
    • npx vitest run src/controllers/openExternal.test.ts (5 tests passed)
    • npx vitest run src/utils/terminal-output.test.ts (3 tests passed)
  • Ran format and lint checks:
    • npx biome check src/utils/env.ts cli/src/utils/openExternal.test.ts (clean, 0 errors)
  • Ran TypeScript compilation checks:
    • npm run typecheck:cli (clean, 0 errors)
    • npm run typecheck:root (clean, 0 errors)

@dirac-run

Copy link
Copy Markdown
Owner

Thanks for the fix!

@dirac-run
dirac-run merged commit 1928234 into dirac-run:master Nov 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows TUI ignores typing until Enter is pressed once

2 participants