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(
943943 match dirs {
944944 Ok ( mut children) => {
945945 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+ } ) ;
948953 }
949954 children. sort_by ( |p1, p2| p2. file_name ( ) . cmp ( & p1. file_name ( ) ) ) ;
950955 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;
1818use glob:: { glob, glob_with} ;
1919use std:: env;
2020use std:: fs;
21- use std:: path:: PathBuf ;
21+ use std:: path:: { Path , PathBuf } ;
2222use tempdir:: TempDir ;
2323
2424#[ test]
2525fn 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+ {
2730 if directory {
2831 fs:: create_dir ( path) . unwrap ( ) ;
2932 } else {
@@ -474,4 +477,23 @@ fn main() {
474477 )
475478 ) ;
476479 }
480+
481+ #[ cfg( target_os = "linux" ) ]
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+ }
477499}
You can’t perform that action at this time.
0 commit comments