File tree Expand file tree Collapse file tree 2 files changed +31
-4
lines changed Expand file tree Collapse file tree 2 files changed +31
-4
lines changed Original file line number Diff line number Diff line change @@ -943,8 +943,13 @@ fn fill_todo(
943
943
match dirs {
944
944
Ok ( mut children) => {
945
945
if options. require_literal_leading_dot {
946
- children
947
- . retain ( |x| !x. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . starts_with ( '.' ) ) ;
946
+ children. retain ( |x| {
947
+ !x. file_name ( )
948
+ . unwrap ( )
949
+ . to_str ( )
950
+ // FIXME (#9639): This needs to handle non-utf8 paths
951
+ . is_none_or ( |s| s. starts_with ( '.' ) )
952
+ } ) ;
948
953
}
949
954
children. sort_by ( |p1, p2| p2. file_name ( ) . cmp ( & p1. file_name ( ) ) ) ;
950
955
todo. extend ( children. into_iter ( ) . map ( |x| Ok ( ( x, idx) ) ) ) ;
Original file line number Diff line number Diff line change @@ -18,12 +18,15 @@ extern crate tempdir;
18
18
use glob:: { glob, glob_with} ;
19
19
use std:: env;
20
20
use std:: fs;
21
- use std:: path:: PathBuf ;
21
+ use std:: path:: { Path , PathBuf } ;
22
22
use tempdir:: TempDir ;
23
23
24
24
#[ test]
25
25
fn main ( ) {
26
- fn mk_file ( path : & str , directory : bool ) {
26
+ fn mk_file < P > ( path : P , directory : bool )
27
+ where
28
+ P : AsRef < Path > ,
29
+ {
27
30
if directory {
28
31
fs:: create_dir ( path) . unwrap ( ) ;
29
32
} else {
@@ -474,4 +477,23 @@ fn main() {
474
477
)
475
478
) ;
476
479
}
480
+
481
+ #[ cfg( unix) ]
482
+ {
483
+ use std:: ffi:: OsString ;
484
+ use std:: os:: unix:: ffi:: OsStringExt ;
485
+
486
+ // create a non-utf8 file
487
+ let non_utf8 = OsString :: from_vec ( b"i/qwe/.\xff \xff \xff \xff " . into ( ) ) ;
488
+ assert ! ( non_utf8. to_str( ) . is_none( ) ) ;
489
+ mk_file ( PathBuf :: from ( non_utf8) , false ) ;
490
+
491
+ // this tests a case where require_literal_leading_dot panicked.
492
+ assert_eq ! ( options. require_literal_leading_dot, true ) ;
493
+ // ensure that we don't panic
494
+ assert_eq ! (
495
+ glob_with_vec( "i/qwe/nothing*" , options) ,
496
+ Vec :: <PathBuf >:: new( )
497
+ ) ;
498
+ }
477
499
}
You can’t perform that action at this time.
0 commit comments