File tree 1 file changed +9
-2
lines changed
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 {
8
8
// have to do a bit of work removing certain prefixes and replacing
9
9
// backslashes.
10
10
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 ( ) {
12
13
match component {
13
14
std:: path:: Component :: Prefix ( prefix) => match prefix. kind ( ) {
14
15
std:: path:: Prefix :: Disk ( letter) | std:: path:: Prefix :: VerbatimDisk ( letter) => {
@@ -26,7 +27,13 @@ pub fn normalize_path(path: &Path) -> String {
26
27
std:: path:: Component :: Normal ( n) => {
27
28
components. push ( n. to_string_lossy ( ) . to_string ( ) ) ;
28
29
}
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
+ }
30
37
std:: path:: Component :: CurDir => { }
31
38
std:: path:: Component :: ParentDir => { }
32
39
}
You can’t perform that action at this time.
0 commit comments