@@ -98,7 +98,14 @@ pub fn normalize_path(path: &Path) -> PathBuf {
98
98
}
99
99
Component :: CurDir => { }
100
100
Component :: ParentDir => {
101
- ret. pop ( ) ;
101
+ if ret. ends_with ( Component :: ParentDir ) {
102
+ ret. push ( Component :: ParentDir ) ;
103
+ } else {
104
+ let popped = ret. pop ( ) ;
105
+ if !popped && !ret. has_root ( ) {
106
+ ret. push ( Component :: ParentDir ) ;
107
+ }
108
+ }
102
109
}
103
110
Component :: Normal ( c) => {
104
111
ret. push ( c) ;
@@ -879,13 +886,13 @@ mod tests {
879
886
( "foo/bar/./././///" , "foo/bar" ) ,
880
887
( "foo/bar/.." , "foo" ) ,
881
888
( "foo/bar/../.." , "" ) ,
882
- ( "foo/bar/../../.." , "" ) ,
883
- ( "../../foo/bar" , "foo/bar" ) ,
884
- ( "../../foo/bar/" , "foo/bar" ) ,
885
- ( "../../foo/bar/./././///" , "foo/bar" ) ,
886
- ( "../../foo/bar/.." , "foo" ) ,
887
- ( "../../foo/bar/../.." , "" ) ,
888
- ( "../../foo/bar/../../.." , "" ) ,
889
+ ( "foo/bar/../../.." , ".. " ) ,
890
+ ( "../../foo/bar" , "../../ foo/bar" ) ,
891
+ ( "../../foo/bar/" , "../../ foo/bar" ) ,
892
+ ( "../../foo/bar/./././///" , "../../ foo/bar" ) ,
893
+ ( "../../foo/bar/.." , "../../ foo" ) ,
894
+ ( "../../foo/bar/../.." , "../.. " ) ,
895
+ ( "../../foo/bar/../../.." , "../../.. " ) ,
889
896
] ;
890
897
for ( input, expected) in cases {
891
898
let actual = normalize_path ( std:: path:: Path :: new ( input) ) ;
0 commit comments