You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
netstandard2.0: relative paths to files gain a trailing separator ("src/file.cs/") and a directory relative to itself is "" so AsAbsolute then throws #385
Semantics.Paths ships a netstandard2.0 target. On that target, PathPolyfill.GetRelativePath (Semantics.Paths/Polyfills.cs L19-46) is used instead of Path.GetRelativePath. The callers are:
AbsoluteDirectoryPath.GetRelativePathTo and AsRelative (Implementations/AbsoluteDirectoryPath.cs:255, :286)
DirectoryPath (Primitives/DirectoryPath.cs:54) and FilePath (Primitives/FilePath.cs:33)
The fallback appends a directory separator to both paths before building Uris, then returns MakeRelativeUri verbatim. That gives two failures that #315 (percent-decoding) does not cover:
A file target gets a trailing separator.src/file.cs comes back as src/file.cs/, because the target was turned into .../file.cs/ before the URI was built. Every AbsoluteFilePath.AsRelative(...) result on netstandard2.0 names a directory-shaped path. Directory results also carry a trailing / (src/) that Path.GetRelativePath never returns, so the same input gives different values and equality on different TFMs.
A directory relative to itself is "", not ".".MakeRelativeUri of two identical URIs is empty, so the result is an empty RelativeDirectoryPath. Resolving it back with AsAbsolute(dir) reaches the netstandard2.0 PathPolyfill.GetFullPath fallback, which throws ArgumentException("Path cannot be empty.") (Polyfills.cs ~L105). On net8+ the same round trip works.
Cross-drive input on Windows (C:\a relative to D:\x) also looks wrong, since both file: URIs share a scheme, so the Scheme check does not catch it. That case is traced from MakeRelativeUri semantics and was not run.
Reproduction
The fallback logic was copied verbatim and run on .NET 10 (Linux) next to Path.GetRelativePath:
Add tests that run against the polyfill directly, since it is internal and InternalsVisibleTo already exists. That gets coverage without a netstandard2.0 test host. Assert that the polyfill matches Path.GetRelativePath for the rows above, plus a nested .. case.
Priority: High. Every AbsoluteFilePath.AsRelative(...) result on the shipped netstandard2.0 target is wrong: a file comes back with a trailing separator. A directory resolved against itself throws on the round trip. Results also differ by TFM, and CI never runs this path.
Suggested area / assignment:Semantics.Paths, PathPolyfill.GetRelativePath (Polyfills.cs)
Recommended next step: Rewrite PathPolyfill.GetRelativePath as a segment-wise common-prefix walk. Then add polyfill-direct tests through the existing InternalsVisibleTo, asserting it matches Path.GetRelativePath for the table rows, plus a nested .. case and the %2E%2E row from #315.
Already fixed on main by #413 (c00d0cd, "Compute RelativePath.Make by comparing paths, not URIs"). On netstandard2.0, PathPolyfill.GetRelativePath now goes through GetRelativePathBySegments, a segment-wise common-prefix walk. It returns . for equal paths, returns path when the roots differ, and never adds a trailing separator. RelativePathMakeTests.SegmentFallback_MatchesPathGetRelativePath checks it against Path.GetRelativePath for every row in this issue's table, plus a nested .. case. Closing.
Activity
matt-edmondson commentedon Oct 6, 2026
Triage
AbsoluteFilePath.AsRelative(...)result on the shippednetstandard2.0target is wrong: a file comes back with a trailing separator. A directory resolved against itself throws on the round trip. Results also differ by TFM, and CI never runs this path.Semantics.Paths,PathPolyfill.GetRelativePath(Polyfills.cs)RelativePath.Makedecodes percent-escapes in real file names, so a folder named%2E%2Ecomes back as..#315 (still open), which covers the percent-decoding half of the same Uri-based fallback. Replacing the polyfill with a segment-wise walk fixes the netstandard2.0 side of both, so one PR should takeRelativePath.Makedecodes percent-escapes in real file names, so a folder named%2E%2Ecomes back as..#315's polyfill half along with this one.RelativePath.Makedecodes percent-escapes in real file names, so a folder named%2E%2Ecomes back as..#315.Recommended next step: Rewrite
PathPolyfill.GetRelativePathas a segment-wise common-prefix walk. Then add polyfill-direct tests through the existingInternalsVisibleTo, asserting it matchesPath.GetRelativePathfor the table rows, plus a nested..case and the%2E%2Erow from #315.Generated by Claude Code
matt-edmondson commentedon Oct 29, 2026
Already fixed on
mainby #413 (c00d0cd, "Compute RelativePath.Make by comparing paths, not URIs"). On netstandard2.0,PathPolyfill.GetRelativePathnow goes throughGetRelativePathBySegments, a segment-wise common-prefix walk. It returns.for equal paths, returnspathwhen the roots differ, and never adds a trailing separator.RelativePathMakeTests.SegmentFallback_MatchesPathGetRelativePathchecks it againstPath.GetRelativePathfor every row in this issue's table, plus a nested..case. Closing.Generated by Claude Code