@@ -197,14 +197,19 @@ impl PosixPath : GenericPath {
197
197
}
198
198
199
199
pure fn push_many ( cs : & [ ~str ] ) -> PosixPath {
200
- PosixPath { components : ( copy self . components ) + copy cs, ..self }
200
+ let mut v = copy self . components ;
201
+ for cs. each |e| {
202
+ let mut ss = str:: split_nonempty ( e, |c| windows:: is_sep ( c as u8 ) ) ;
203
+ unchecked { vec : : push_all_move ( v, move ss) ; }
204
+ }
205
+ PosixPath { components : move v, ..self }
201
206
}
202
207
203
208
pure fn push ( s : & str ) -> PosixPath {
204
- let mut cs = copy self . components ;
205
- unchecked { vec : : push ( cs , move str :: from_slice ( s ) ) ; }
206
- return PosixPath { components : move cs ,
207
- ..self }
209
+ let mut v = copy self . components ;
210
+ let mut ss = str :: split_nonempty ( s , |c| windows :: is_sep ( c as u8 ) ) ;
211
+ unchecked { vec : : push_all_move ( v , move ss ) ; }
212
+ PosixPath { components : move v , ..self }
208
213
}
209
214
210
215
pure fn pop( ) -> PosixPath {
@@ -385,15 +390,19 @@ impl WindowsPath : GenericPath {
385
390
}
386
391
387
392
pure fn push_many ( cs : & [ ~str ] ) -> WindowsPath {
388
- return WindowsPath { components : ( copy self . components ) + ( copy cs) ,
389
- ..self }
393
+ let mut v = copy self . components ;
394
+ for cs. each |e| {
395
+ let mut ss = str:: split_nonempty ( e, |c| windows:: is_sep ( c as u8 ) ) ;
396
+ unchecked { vec : : push_all_move ( v, move ss) ; }
397
+ }
398
+ return WindowsPath { components : move v, ..self }
390
399
}
391
400
392
401
pure fn push ( s : & str ) -> WindowsPath {
393
- let mut cs = copy self . components ;
394
- unchecked { vec : : push ( cs , move str :: from_slice ( s ) ) ; }
395
- return WindowsPath { components : move cs ,
396
- ..self }
402
+ let mut v = copy self . components ;
403
+ let mut ss = str :: split_nonempty ( s , |c| windows :: is_sep ( c as u8 ) ) ;
404
+ unchecked { vec : : push_all_move ( v , move ss ) ; }
405
+ return WindowsPath { components : move v , ..self }
397
406
}
398
407
399
408
pure fn pop( ) -> WindowsPath {
@@ -419,6 +428,7 @@ pure fn normalize(components: &[~str]) -> ~[~str] {
419
428
for components. each |c| {
420
429
unchecked {
421
430
if c == ~". " && components. len ( ) > 1 { loop ; }
431
+ if c == ~"" { loop ; }
422
432
if c == ~".." && cs.len() != 0 {
423
433
vec::pop(cs);
424
434
loop;
@@ -430,6 +440,20 @@ pure fn normalize(components: &[~str]) -> ~[~str] {
430
440
move cs
431
441
}
432
442
443
+ #[test]
444
+ fn test_double_slash_collapsing()
445
+ {
446
+ let path = from_str::<PosixPath>(" tmp/") ;
447
+ let path = path. push ( "/hmm" ) ;
448
+ let path = path. normalize ( ) ;
449
+ assert ~"tmp/hmm" == path. to_str ( ) ;
450
+
451
+ let path = from_str :: < WindowsPath > ( "tmp/" ) ;
452
+ let path = path. push ( "/hmm" ) ;
453
+ let path = path. normalize ( ) ;
454
+ assert ~"tmp\\ hmm" == path. to_str ( ) ;
455
+ }
456
+
433
457
mod posix {
434
458
435
459
#[ cfg( test) ]
0 commit comments