Repository navigation
[patch] Compute RelativePath.Make by comparing paths, not URIs - #413
Merged
Merged
Conversation
Make built System.Uri values from file-system paths and unescaped the result, so a literal percent sequence in a name was decoded: a folder named "%2E%2E" came back as "..", escaping the base directory. Make now uses Path.GetRelativePath (through PathPolyfill), resolving a non-directory "from" from the directory that contains it as before. The netstandard2.0 fallback, which had the same Uri flaw, now compares path segments, so it also stops adding a trailing separator to file targets and returns "." for a directory relative to itself. Fixes #315 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A5MkmzQ4qxxRmHStdQ8oJA
Path.Combine drops earlier arguments when a later one is rooted, which would mask a rooted result from Make. Path.Join keeps every segment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A5MkmzQ4qxxRmHStdQ8oJA
|
This was referenced Oct 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #315
What was wrong
SemanticRelativePath.MakebuiltSystem.Urivalues from file-system paths and passed the result throughUri.UnescapeDataString. On Linux, macOS and Windows alike,%is an ordinary file-name character, so a literal percent sequence in a name got decoded. A folder named%2E%2Ecame back as.., which escapes the base directory. The netstandard2.0 fallbackPathPolyfill.GetRelativePathused the same Uri approach.Change
Make(Semantics.Paths/SemanticRelativePath.cs) now callsPathPolyfill.GetRelativePath, which isPath.GetRelativePathon every target except netstandard2.0. Existing behaviour is kept in two ways:fromthat is not anIDirectoryPathis still resolved from the directory that contains it, as the Uri version did/The netstandard2.0 fallback is now
GetRelativePathBySegments. It does a full-path, segment-by-segment comparison:Path.GetRelativePathispathwhen the roots differ.when both paths name the same directoryIt is compiled on every target so it can be tested against
Path.GetRelativePath. The fallback is no longer Uri-based, so the now-unusedAppendDirectorySeparatorCharhelper is removed.Related: the new fallback also removes both netstandard2.0 failures described in #385: a file target no longer gains a trailing separator, and a directory relative to itself is
.rather than"". I left #385 open because the test project only runs on net10.0, so that target is covered by the equivalence test below rather than by a test running on netstandard2.0.Behaviour change on net8+:
Makefrom a directory to itself now returns.instead of an empty path, matchingPath.GetRelativePathand the siblingGetRelativePathTo/AsRelativeAPIs.Tests (
Semantics.Test/Paths/RelativePathMakeTests.cs)Make_KeepsPercentSequencesInNamesAsWritten: the four rows from the issue plus50%20off. The result equals the name as written, and resolving it againstfromgivesto. The four issue rows failed before the fix.Make_FromAFile_IsRelativeToItsDirectory: pins the existing non-directoryfrombehaviour.SegmentFallback_MatchesPathGetRelativePath: eight cases (percent names, file target, child directory, self, sibling subtree, ancestor, a space in a name, from the root). The new fallback matchesPath.GetRelativePathon all eight. Swapping the old Uri-based logic in temporarily made all eight fail.Semantics.Teston net10.0: 1494 passed, 8 skipped, 0 failed.Semantics.Pathsbuilds for all five TFMs with the local Sonar analyzers, with no findings on the changed files.🤖 Generated with Claude Code
https://claude.ai/code/session_01A5MkmzQ4qxxRmHStdQ8oJA
Generated by Claude Code