@@ -97,13 +97,13 @@ impl GenericPathUnsafe for Path {
97
97
Some ( 0 ) if self . repr . len ( ) == 1 && self . repr [ 0 ] == sep => {
98
98
self . repr = Path :: normalize ( dirname) ;
99
99
}
100
+ Some ( idx) if self . repr . slice_from ( idx+1 ) == bytes ! ( ".." ) => {
101
+ self . repr = Path :: normalize ( dirname) ;
102
+ }
100
103
Some ( idx) if dirname. is_empty ( ) => {
101
104
let v = Path :: normalize ( self . repr . slice_from ( idx+1 ) ) ;
102
105
self . repr = v;
103
106
}
104
- Some ( idx) if self . repr . slice_from ( idx+1 ) == bytes ! ( ".." ) => {
105
- self . repr = Path :: normalize ( dirname) ;
106
- }
107
107
Some ( idx) => {
108
108
let mut v = vec:: with_capacity ( dirname. len ( ) + self . repr . len ( ) - idx) ;
109
109
v. push_all ( dirname) ;
@@ -444,7 +444,9 @@ mod tests {
444
444
t ! ( s: Path :: from_str( "" ) , "." ) ;
445
445
t ! ( s: Path :: from_str( "/" ) , "/" ) ;
446
446
t ! ( s: Path :: from_str( "hi" ) , "hi" ) ;
447
+ t ! ( s: Path :: from_str( "hi/" ) , "hi" ) ;
447
448
t ! ( s: Path :: from_str( "/lib" ) , "/lib" ) ;
449
+ t ! ( s: Path :: from_str( "/lib/" ) , "/lib" ) ;
448
450
t ! ( s: Path :: from_str( "hi/there" ) , "hi/there" ) ;
449
451
t ! ( s: Path :: from_str( "hi/there.txt" ) , "hi/there.txt" ) ;
450
452
@@ -800,6 +802,8 @@ mod tests {
800
802
t!(s: Path::from_str(" /foo").with_dirname_str(" bar"), " bar/foo");
801
803
t!(s: Path::from_str(" ..").with_dirname_str(" foo"), " foo");
802
804
t!(s: Path::from_str(" ../..").with_dirname_str(" foo"), " foo");
805
+ t!(s: Path::from_str(" ..").with_dirname_str(" "), " . ");
806
+ t!(s: Path::from_str(" ../..").with_dirname_str(" "), " . ");
803
807
t!(s: Path::from_str(" foo").with_dirname_str(" .."), " ../foo");
804
808
t!(s: Path::from_str(" foo").with_dirname_str(" ../.."), " ../../foo");
805
809
@@ -813,6 +817,8 @@ mod tests {
813
817
t!(s: Path::from_str(" /").with_filename_str(" foo"), " /foo");
814
818
t!(s: Path::from_str(" /a").with_filename_str(" foo"), " /foo");
815
819
t!(s: Path::from_str(" foo").with_filename_str(" bar"), " bar");
820
+ t!(s: Path::from_str(" /").with_filename_str(" foo/"), " /foo");
821
+ t!(s: Path::from_str(" /a").with_filename_str(" foo/"), " /foo");
816
822
t!(s: Path::from_str(" a/b/c").with_filename_str(" "), " a/b");
817
823
t!(s: Path::from_str(" a/b/c").with_filename_str(" . "), " a/b");
818
824
t!(s: Path::from_str(" a/b/c").with_filename_str(" .."), " a");
@@ -822,6 +828,8 @@ mod tests {
822
828
t!(s: Path::from_str(" a/b/c").with_filename_str(" /d"), " a/b/d");
823
829
t!(s: Path::from_str(" ..").with_filename_str(" foo"), " ../foo");
824
830
t!(s: Path::from_str(" ../..").with_filename_str(" foo"), " ../../foo");
831
+ t!(s: Path::from_str(" ..").with_filename_str(" "), " ..");
832
+ t!(s: Path::from_str(" ../..").with_filename_str(" "), " ../..");
825
833
826
834
t!(v: Path::new(b!(" hi/there", 0x80, " . txt")).with_filestem(b!(0xff)),
827
835
b!(" hi/", 0xff, " . txt"));
0 commit comments