File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed
Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,8 @@ pub fn normalize_path(path: &Path) -> String {
88 // have to do a bit of work removing certain prefixes and replacing
99 // backslashes.
1010 let mut components: Vec < String > = Vec :: new ( ) ;
11- for component in path. components ( ) {
11+ let mut path_components = path. components ( ) . peekable ( ) ;
12+ while let Some ( component) = path_components. next ( ) {
1213 match component {
1314 std:: path:: Component :: Prefix ( prefix) => match prefix. kind ( ) {
1415 std:: path:: Prefix :: Disk ( letter) | std:: path:: Prefix :: VerbatimDisk ( letter) => {
@@ -26,7 +27,13 @@ pub fn normalize_path(path: &Path) -> String {
2627 std:: path:: Component :: Normal ( n) => {
2728 components. push ( n. to_string_lossy ( ) . to_string ( ) ) ;
2829 }
29- std:: path:: Component :: RootDir => { }
30+ std:: path:: Component :: RootDir => {
31+ if path_components. peek ( ) . is_none ( ) {
32+ // The path points at a root directory, so we need to add a
33+ // trailing slash, e.g. `C:/` instead of `C:`.
34+ components. push ( "" . to_string ( ) ) ;
35+ }
36+ }
3037 std:: path:: Component :: CurDir => { }
3138 std:: path:: Component :: ParentDir => { }
3239 }
You can’t perform that action at this time.
0 commit comments