@@ -449,24 +449,44 @@ impl PartialConfigurationExt for PartialConfiguration {
449
449
/// Normalizes a path, resolving '..' and '.' segments without requiring the path to exist
450
450
fn normalize_path ( path : & Path ) -> PathBuf {
451
451
let mut components = Vec :: new ( ) ;
452
+ let mut has_root_or_prefix = false ;
453
+
452
454
for component in path. components ( ) {
453
455
match component {
454
456
std:: path:: Component :: ParentDir => {
455
- if !components. is_empty ( ) {
457
+ if !components. is_empty ( )
458
+ && !matches ! ( components. last( ) , Some ( c) if matches!( Path :: new( c) . components( ) . next( ) ,
459
+ Some ( std:: path:: Component :: Prefix ( _) ) ) )
460
+ {
456
461
components. pop ( ) ;
457
462
}
458
463
}
459
464
std:: path:: Component :: Normal ( c) => components. push ( c) ,
460
465
std:: path:: Component :: CurDir => { }
461
- c @ std:: path:: Component :: RootDir | c @ std:: path:: Component :: Prefix ( _) => {
466
+ c @ std:: path:: Component :: RootDir => {
467
+ has_root_or_prefix = true ;
468
+ components. clear ( ) ;
469
+ components. push ( c. as_os_str ( ) ) ;
470
+ }
471
+ c @ std:: path:: Component :: Prefix ( _) => {
472
+ has_root_or_prefix = true ;
462
473
components. clear ( ) ;
463
474
components. push ( c. as_os_str ( ) ) ;
464
475
}
465
476
}
466
477
}
467
478
468
479
if components. is_empty ( ) {
469
- PathBuf :: from ( "/" )
480
+ if has_root_or_prefix {
481
+ // On Windows, this would be something like "C:\" or "\"
482
+ path. ancestors ( )
483
+ . last ( )
484
+ . unwrap_or ( Path :: new ( "" ) )
485
+ . to_path_buf ( )
486
+ } else {
487
+ // Return current directory as a relative path
488
+ PathBuf :: from ( "." )
489
+ }
470
490
} else {
471
491
let mut result = PathBuf :: new ( ) ;
472
492
for component in components {
0 commit comments