@@ -8,12 +8,11 @@ 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- let mut is_disk = false ;
12- for component in path . components ( ) {
11+ let mut path_components = path . components ( ) . peekable ( ) ;
12+ while let Some ( component) = path_components . next ( ) {
1313 match component {
1414 std:: path:: Component :: Prefix ( prefix) => match prefix. kind ( ) {
1515 std:: path:: Prefix :: Disk ( letter) | std:: path:: Prefix :: VerbatimDisk ( letter) => {
16- is_disk = true ;
1716 components. push ( format ! ( "{}:" , letter as char ) ) ;
1817 }
1918 std:: path:: Prefix :: Verbatim ( x) | std:: path:: Prefix :: DeviceNS ( x) => {
@@ -28,16 +27,17 @@ pub fn normalize_path(path: &Path) -> String {
2827 std:: path:: Component :: Normal ( n) => {
2928 components. push ( n. to_string_lossy ( ) . to_string ( ) ) ;
3029 }
31- 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+ }
3237 std:: path:: Component :: CurDir => { }
3338 std:: path:: Component :: ParentDir => { }
3439 }
3540 }
36- if components. len ( ) == 1 && is_disk {
37- // If the path is just a drive letter, we need to add a trailing
38- // slash to match the CodeQL spec.
39- components. push ( "" . to_string ( ) ) ;
40- }
4141 components. join ( "/" )
4242 } else {
4343 // For other operating systems, we can use the canonicalized path
0 commit comments