-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Normalize Windows workspace path casing to NTFS canonical form #4406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
salmanmkc
wants to merge
4
commits into
main
Choose a base branch
from
fix/normalize-windows-path-casing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+297
−1
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7585eb3
Normalize Windows path casing using GetFinalPathNameByHandle
salmanmkc 8307b8f
Handle long paths, UNC paths, and UNC temp in tests
salmanmkc fffded9
Cache canonical root path to avoid repeated API calls
salmanmkc ed0e5b7
Add regression tests for path casing normalization
salmanmkc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| using GitHub.Runner.Sdk; | ||
| using System.IO; | ||
| using System.Runtime.InteropServices; | ||
|
salmanmkc marked this conversation as resolved.
|
||
| using Xunit; | ||
|
|
||
| namespace GitHub.Runner.Common.Tests.Util | ||
| { | ||
| public sealed class PathUtilL0 | ||
| { | ||
| [Fact] | ||
| [Trait("Level", "L0")] | ||
| [Trait("Category", "Common")] | ||
| public void GetCanonicalPath_ReturnsPath_WhenDirectoryDoesNotExist() | ||
| { | ||
| var fakePath = Path.Combine(Path.GetTempPath(), "nonexistent_" + Path.GetRandomFileName()); | ||
| var result = PathUtil.GetCanonicalPath(fakePath); | ||
| Assert.Equal(fakePath, result); | ||
| } | ||
|
|
||
| [Fact] | ||
| [Trait("Level", "L0")] | ||
| [Trait("Category", "Common")] | ||
| public void GetCanonicalPath_ReturnsPath_WhenNull() | ||
| { | ||
| Assert.Null(PathUtil.GetCanonicalPath(null)); | ||
| } | ||
|
|
||
| [Fact] | ||
| [Trait("Level", "L0")] | ||
| [Trait("Category", "Common")] | ||
| public void GetCanonicalPath_ReturnsEmpty_WhenEmpty() | ||
| { | ||
| Assert.Equal(string.Empty, PathUtil.GetCanonicalPath(string.Empty)); | ||
| } | ||
|
|
||
| [Fact] | ||
| [Trait("Level", "L0")] | ||
| [Trait("Category", "Common")] | ||
| public void GetCanonicalPath_ReturnsValidPath_ForExistingDirectory() | ||
| { | ||
| var tempDir = Path.Combine(Path.GetTempPath(), "pathutil_test_" + Path.GetRandomFileName()); | ||
| try | ||
| { | ||
| Directory.CreateDirectory(tempDir); | ||
| var result = PathUtil.GetCanonicalPath(tempDir); | ||
| Assert.NotNull(result); | ||
| Assert.True(Directory.Exists(result)); | ||
| } | ||
| finally | ||
| { | ||
| if (Directory.Exists(tempDir)) | ||
| { | ||
| Directory.Delete(tempDir); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #if OS_WINDOWS | ||
| [Fact] | ||
| [Trait("Level", "L0")] | ||
| [Trait("Category", "Common")] | ||
| public void GetCanonicalPath_NormalizesDriveLetter_OnWindows() | ||
| { | ||
| var tempDir = Path.GetTempPath().TrimEnd(Path.DirectorySeparatorChar); | ||
|
|
||
| // Skip if temp is a UNC path (no drive letter to normalize) | ||
| if (tempDir.StartsWith(@"\\")) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| // Force lowercase drive letter | ||
| var lowerCased = char.ToLower(tempDir[0]) + tempDir.Substring(1); | ||
|
|
||
| var result = PathUtil.GetCanonicalPath(lowerCased); | ||
|
|
||
| // The canonical path should have an uppercase drive letter | ||
| Assert.True(char.IsUpper(result[0]), | ||
| $"Expected uppercase drive letter but got: {result}"); | ||
| } | ||
|
|
||
| [Fact] | ||
| [Trait("Level", "L0")] | ||
| [Trait("Category", "Common")] | ||
| public void GetCanonicalPath_NormalizesFolderCasing_OnWindows() | ||
| { | ||
| // Create a directory with known casing, then query with wrong casing | ||
| var basePath = Path.GetTempPath(); | ||
| if (basePath.StartsWith(@"\\")) | ||
| { | ||
| return; // Skip UNC | ||
| } | ||
|
|
||
| var realName = "PathUtilTest_MiXeDcAsE_" + Path.GetRandomFileName(); | ||
| var realDir = Path.Combine(basePath, realName); | ||
| try | ||
| { | ||
| Directory.CreateDirectory(realDir); | ||
|
|
||
| // Query with all-lowercase version | ||
| var wrongCased = Path.Combine(basePath, realName.ToLowerInvariant()); | ||
|
|
||
| var result = PathUtil.GetCanonicalPath(wrongCased); | ||
|
|
||
| // The canonical result should contain the original mixed-case name | ||
| Assert.Contains(realName, result); | ||
| } | ||
| finally | ||
| { | ||
| if (Directory.Exists(realDir)) | ||
| { | ||
| Directory.Delete(realDir); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| [Trait("Level", "L0")] | ||
| [Trait("Category", "Common")] | ||
| public void GetCanonicalPath_IsIdempotent_OnWindows() | ||
| { | ||
| // Calling GetCanonicalPath twice should return the same result | ||
| var tempDir = Path.GetTempPath().TrimEnd(Path.DirectorySeparatorChar); | ||
| var first = PathUtil.GetCanonicalPath(tempDir); | ||
| var second = PathUtil.GetCanonicalPath(first); | ||
| Assert.Equal(first, second); | ||
| } | ||
|
|
||
| [Fact] | ||
| [Trait("Level", "L0")] | ||
| [Trait("Category", "Common")] | ||
| public void GetCanonicalPath_ReturnsSameResult_RegardlessOfInputCasing_OnWindows() | ||
| { | ||
| var tempDir = Path.GetTempPath().TrimEnd(Path.DirectorySeparatorChar); | ||
| if (tempDir.StartsWith(@"\\")) | ||
| { | ||
| return; // Skip UNC | ||
| } | ||
|
|
||
| var upper = tempDir.ToUpperInvariant(); | ||
| var lower = tempDir.ToLowerInvariant(); | ||
|
|
||
| var resultUpper = PathUtil.GetCanonicalPath(upper); | ||
| var resultLower = PathUtil.GetCanonicalPath(lower); | ||
|
|
||
| // Both should resolve to the same canonical path | ||
| Assert.Equal(resultUpper, resultLower); | ||
| } | ||
| #endif | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.