Skip to content

fix(resolve): preserve UNC prefix (#245) - #246

Merged
pi0 merged 1 commit into
mainfrom
fix/unc
Jul 8, 2026
Merged

pi0 merged 1 commit into
mainfrom
fix/unc

Conversation

@pi0x

@pi0x pi0x commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #245

Problem

resolve() collapsed the leading // of a Windows UNC path down to a single /, breaking network paths:

resolve("\\\\unc-server-name\\unc-path")
// was: "/unc-server-name/unc-path"   ❌
// now: "//unc-server-name/unc-path"  ✅

normalizeString() merges consecutive slashes, so the UNC // prefix was lost. normalize() already re-applied the prefix via its isUNCPath branch, but resolve() had no equivalent — so the two disagreed.

Fix

Track whether the terminating (base) segment is a UNC path and re-apply the // prefix after normalization in resolve(), mirroring normalize(). The flag is tested against the source segment rather than the concatenated resolvedPath, which can spuriously start with // when joining a / root (e.g. resolve("/", "file.txt")).

Per pathe's forward-slash convention, UNC paths are represented as //server/share/... (matching the existing normalize() output and path.win32.resolve's slash count), not Node's back-slash form.

Tests

Added UNC cases to the resolve suite:

resolve(\\server\share\file)           →  //server/share/file
resolve(\\server\share\file, ..\path)  →  //server/share/path
resolve(\\server\share\file, sub)      →  //server/share/file/sub
resolve(\\unc-server-name\unc-path)    →  //unc-server-name/unc-path

Full suite passes; lint / format / typecheck clean.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved path resolution for UNC/network paths so double-slash prefixes are preserved correctly.
    • Fixed resolution behavior when combining UNC paths with relative segments, including .. and nested subpaths.
  • Tests

    • Added coverage for UNC path resolution scenarios to verify expected output across multiple cases.

`resolve()` collapsed the leading `//` of a UNC path (e.g.
`\\server\share`) down to a single `/` because `normalizeString`
merges consecutive slashes. `normalize()` already re-applied the UNC
prefix; mirror that in `resolve()` so both agree and match
`path.win32.resolve`.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@pi0 pi0 changed the title fix: preserve UNC prefix in resolve (#245) fix(resolve): preserve UNC prefix (#245) Jul 8, 2026
@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e96a8ebc-68fa-4dd2-8533-ded332c49309

📥 Commits

Reviewing files that changed from the base of the PR and between 55a21be and 33d21b4.

📒 Files selected for processing (2)
  • src/_path.ts
  • test/index.spec.ts

📝 Walkthrough

Walkthrough

The resolve() function in src/_path.ts now detects when the base absolute segment is a UNC path (e.g., \\server\share) and preserves the double-slash UNC prefix in its return value instead of falling through to standard path normalization. Test cases were added to verify this behavior.

Changes

UNC path resolution fix

Layer / File(s) Summary
Track and preserve UNC prefix in resolve()
src/_path.ts
Introduces a resolvedUNC flag set when a UNC-pattern segment is detected during argument processing, and returns a //...-prefixed path when the flag is true instead of standard absolute/relative normalization.
UNC path test cases
test/index.spec.ts
Adds resolve test cases asserting correct //server/share/... results for UNC base paths alone and combined with relative segments and subpaths.

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

Suggested reviewers: pi0

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/unc

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

Comment @coderabbitai help to get the list of available commands.

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.

resolve breaks Windows UNC Paths

2 participants