Skip to content
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

port namespace fix #53786

Merged
merged 3 commits into from
Jun 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -383,5 +383,21 @@ public void CombinePaths_DifferentFromPathCombine(string expected, string path1,
{
Assert.Equal(expected, PathUtilities.CombinePaths(path1, path2));
}

[ConditionalFact(typeof(WindowsOnly)), WorkItem(51602, @"https://github.com/dotnet/roslyn/issues/51602")]
public void GetRelativePath_EnsureNo_IndexOutOfRangeException_Windows()
{
var expected = "";
var result = PathUtilities.GetRelativePath(@"C:\A\B\", @"C:\A\B");
Assert.Equal(expected, result);
}

[ConditionalFact(typeof(UnixLikeOnly)), WorkItem(51602, @"https://github.com/dotnet/roslyn/issues/51602")]
public void GetRelativePath_EnsureNo_IndexOutOfRangeException_Unix()
{
var expected = "";
var result = PathUtilities.GetRelativePath(@"/A/B/", @"/A/B");
Assert.Equal(expected, result);
}
}
}
3 changes: 3 additions & 0 deletions src/Compilers/Core/Portable/FileSystem/PathUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,9 @@ public static string GetRelativePath(string directory, string fullPath)
{
string relativePath = string.Empty;

directory = TrimTrailingSeparators(directory);
fullPath = TrimTrailingSeparators(fullPath);

if (IsChildPath(directory, fullPath))
{
return GetRelativeChildPath(directory, fullPath);
Expand Down