Skip to content

fix(parseURL): anchor Windows file path normalization - #413

Open
monishpeddapally wants to merge 1 commit into
unjs:mainfrom
monishpeddapally:fix/file-drive-path-boundary
Open

monishpeddapally wants to merge 1 commit into
unjs:mainfrom
monishpeddapally:fix/file-drive-path-boundary

Conversation

@monishpeddapally

@monishpeddapally monishpeddapally commented Nov 9, 2026 •

Copy link
Copy Markdown

File URL parsing currently removes the first slash before a drive-like segment anywhere in the path, query, or fragment. For example, parseURL("file:///tmp/C:/file.txt").pathname returns "/tmpC:/file.txt", and ?next=/C:/data becomes ?next=C:/data.

Anchor the existing normalization pattern to the start of the path so nested path segments, queries, and fragments retain their slashes. Add eight cases covering these regressions and the existing leading Windows drive behavior.

Validation

  • Six new cases fail against unchanged main; the two Windows drive controls pass.
  • corepack pnpm test: all 499 tests pass, including lint, formatting, and type checks.
  • corepack pnpm build: passes.
  • Built ESM and CommonJS outputs match native URL for the six affected inputs and round-trip through stringifyParsedURL.
  • git diff --check: passes.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected parsing of file: URLs so slashes are removed only when they immediately precede a drive-letter path. Query strings and fragments are preserved correctly, including for localhost and server-share URLs.

@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

parseURL now removes a slash before a drive letter only when the slash is at the start of a file: URL path. Tests cover drive-like segments in the pathname, query, and fragment.

Changes: File URL parsing

Layer / File(s) Summary
Drive-path parsing and regression cases
src/parse.ts, test/parse.test.ts
The drive-prefix slash adjustment applies only at the start of the path. Eight test cases check that drive-like segments remain assigned to the expected pathname, search, and hash components.

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Bug fix

Possibly related issues

Possibly related PRs

  • unjs/ufo#412 — Both PRs change the file: drive-letter adjustment in parseURL, covering the protocol check and the slash-removal condition.
Merge Risk: Minimal · up to 2e385

The change narrows drive-path normalization; no merge-blocking risk is identified.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the parseURL function and the Windows file path normalization. The change limits removal of the leading slash before a drive-letter path to the start of the file URL path, so the title…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the parseURL function and the Windows file path normalization. The change limits removal of the leading slash before a drive-letter path to the start of the file URL path, so the title matches the main change. The title uses a conventional fix(...) prefix and is concise, although "anchor" is slightly technical. It is clear enough for a teammate scanning history to understand the primary change.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ff8a389e-6711-43e5-badf-10475d195426
Commits

Reviewing files that changed from the base of the PR and between f06c800 and 2e38511.

Files selected for processing: 2

  • src/parse.ts
  • test/parse.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

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.

1 participant