Skip to content

Add ToUri and FromUri to ChainablePath - #157

Merged
dennisdoomen merged 2 commits into
mainfrom
dennisdoomen-issue-146-touri-fromuri
Aug 10, 2026
Merged

Add ToUri and FromUri to ChainablePath#157
dennisdoomen merged 2 commits into
mainfrom
dennisdoomen-issue-146-touri-fromuri

Conversation

@dennisdoomen

@dennisdoomen dennisdoomen commented Aug 10, 2026

Copy link
Copy Markdown
Owner

Summary

Implements the API proposal in #146:

public Uri ToUri();
public static ChainablePath FromUri(Uri uri);

Design decisions

  • ToUri() throws on relative paths instead of silently resolving against the current working directory. Implicitly resolving against cwd would be a surprising side effect for a path library — the caller should make that resolution explicit (e.g. via ToAbsolute()) before calling ToUri(). Throws InvalidOperationException with a message stating the path must be absolute.
  • ToUri() delegates to new Uri(string) for absolute paths rather than hand-rolling escaping logic. The built-in constructor already produces correct file:// URIs (with proper percent-escaping) for both regular absolute paths and UNC paths.
  • FromUri(Uri) restricts to the file scheme and requires an absolute Uri, throwing ArgumentException otherwise (mentioning the rejected scheme), and ArgumentNullException for a null Uri. It builds the ChainablePath from uri.LocalPath, which already handles UNC paths and percent-decoding correctly.
  • No implicit conversion to/from Uri was added (per the issue's rejected alternatives), and FromUri only accepts a Uri, not a string, keeping the surface minimal as scoped in the issue.

Testing

  • Added unit tests in Pathy.Specs/ChainablePathSpecs.cs covering: absolute path round-trip through ToUri/FromUri, relative path throwing on ToUri, UNC path handling, rejection of non-file schemes, rejection of relative URIs, null-uri check, and paths with spaces/special characters.
  • dotnet test Pathy.Specs — 117 passed (net8.0).
  • dotnet test Pathy.ApiVerificationTests — 8 passed across all four target frameworks (net47, net8.0, netstandard2.0, netstandard2.1) after regenerating the approved API snapshots via AcceptApiChanges.ps1.

Fixes #146

Dennis Doomen and others added 2 commits November 26, 2025 15:21
Implements the API proposal in issue #146.

- ToUri() converts an absolute ChainablePath to a file:// Uri by
  delegating to the built-in Uri(string) constructor, which already
  handles escaping and UNC paths correctly. Throws
  InvalidOperationException for relative paths instead of silently
  resolving against the current directory, since that would be an
  implicit and surprising side effect for a path library.
- FromUri(Uri) validates the Uri is absolute and uses the file
  scheme (throwing ArgumentException otherwise, and
  ArgumentNullException for a null Uri), then builds a ChainablePath
  from uri.LocalPath, which already handles UNC paths and
  percent-decoding.
- Added unit tests covering round-tripping absolute paths, UNC
  paths, and paths with spaces/special characters, plus the relative
  path / non-file-scheme / relative Uri / null Uri failure cases.
- Updated the approved API snapshots for all four target
  frameworks.

Fixes #146

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

Test Results

125 tests  +8   125 ✅ +8   0s ⏱️ -1s
  3 suites ±0     0 💤 ±0 
  3 files   ±0     0 ❌ ±0 

Results for commit 3e85480. ± Comparison against base commit adc85ae.

@dennisdoomen dennisdoomen added the enhancement New feature or request label Aug 10, 2026
@dennisdoomen dennisdoomen changed the title Add ToUri and FromUri to ChainablePath (#146) Add ToUri and FromUri to ChainablePath Aug 10, 2026
@dennisdoomen
dennisdoomen merged commit acd0ead into main Aug 10, 2026
6 checks passed
@dennisdoomen
dennisdoomen deleted the dennisdoomen-issue-146-touri-fromuri branch August 10, 2026 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API Proposal]: ToUri and FromUri

1 participant