File tree 2 files changed +27
-3
lines changed
2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,19 @@ public void TestFileSystemInvalidDriveLetterOnWindows()
31
31
}
32
32
}
33
33
34
+ [ SkippableFact ]
35
+ public void TestRootedPathWithoutDriveOnWindows ( )
36
+ {
37
+ Skip . IfNot ( IsWindows , "Testing Windows-specific behavior" ) ;
38
+
39
+ var driveLetter = Directory . GetCurrentDirectory ( ) [ 0 ] ;
40
+ var fs = new PhysicalFileSystem ( ) ;
41
+
42
+ var resolvedPath = fs . ConvertPathFromInternal ( "/test" ) ;
43
+
44
+ Assert . Equal ( $ "/mnt/{ driveLetter } /test", resolvedPath . ToString ( ) , StringComparer . OrdinalIgnoreCase ) ;
45
+ }
46
+
34
47
[ Fact ]
35
48
public void TestWatcher ( )
36
49
{
Original file line number Diff line number Diff line change @@ -977,9 +977,12 @@ protected override UPath ConvertPathFromInternalImpl(string innerPath)
977
977
if ( innerPath . StartsWith ( @"\\" , StringComparison . Ordinal ) || innerPath . StartsWith ( @"\?" , StringComparison . Ordinal ) )
978
978
throw new NotSupportedException ( $ "Path starting with `\\ \\ ` or `\\ ?` are not supported -> `{ innerPath } ` ") ;
979
979
980
- var absolutePath = Path . IsPathRooted ( innerPath ) ? innerPath : Path . GetFullPath ( innerPath ) ;
981
- var driveIndex = absolutePath . IndexOf ( ":\\ " , StringComparison . Ordinal ) ;
982
- if ( driveIndex != 1 )
980
+ // We want to avoid using Path.GetFullPath unless absolutely necessary,
981
+ // because it can change the case of already rooted paths that contain a ~
982
+ var absolutePath = HasWindowsVolumeLabel ( innerPath ) ? innerPath : Path . GetFullPath ( innerPath ) ;
983
+
984
+ // Assert that Path.GetFullPath returned the format we expect
985
+ if ( ! HasWindowsVolumeLabel ( absolutePath ) )
983
986
throw new ArgumentException ( $ "Expecting a drive for the path `{ absolutePath } `") ;
984
987
985
988
var builder = UPath . GetSharedStringBuilder ( ) ;
@@ -1032,4 +1035,12 @@ private static bool IsDriveLetter(char c)
1032
1035
{
1033
1036
return c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' ;
1034
1037
}
1038
+
1039
+ private static bool HasWindowsVolumeLabel ( string path )
1040
+ {
1041
+ if ( ! IsOnWindows )
1042
+ throw new NotSupportedException ( $ "{ nameof ( HasWindowsVolumeLabel ) } is only supported on Windows platforms." ) ;
1043
+
1044
+ return path . Length >= 3 && path [ 1 ] == ':' && path [ 2 ] is '\\ ' or '/' ;
1045
+ }
1035
1046
}
You can’t perform that action at this time.
0 commit comments