Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -943,8 +943,13 @@ fn fill_todo(
match dirs {
Ok(mut children) => {
if options.require_literal_leading_dot {
children
.retain(|x| !x.file_name().unwrap().to_str().unwrap().starts_with('.'));
children.retain(|x| {
!x.file_name()
.unwrap()
.to_str()
// FIXME (#9639): This needs to handle non-utf8 paths
.is_none_or(|s| s.starts_with('.'))
});
}
children.sort_by(|p1, p2| p2.file_name().cmp(&p1.file_name()));
todo.extend(children.into_iter().map(|x| Ok((x, idx))));
Expand Down
26 changes: 24 additions & 2 deletions tests/glob-std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ extern crate tempdir;
use glob::{glob, glob_with};
use std::env;
use std::fs;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use tempdir::TempDir;

#[test]
fn main() {
fn mk_file(path: &str, directory: bool) {
fn mk_file<P>(path: P, directory: bool)
where
P: AsRef<Path>,
{
if directory {
fs::create_dir(path).unwrap();
} else {
Expand Down Expand Up @@ -474,4 +477,23 @@ fn main() {
)
);
}

#[cfg(target_os = "linux")]
{
use std::ffi::OsString;
use std::os::unix::ffi::OsStringExt;

// create a non-utf8 file
let non_utf8 = OsString::from_vec(b"i/qwe/.\xff\xff\xff\xff".into());
assert!(non_utf8.to_str().is_none());
mk_file(PathBuf::from(non_utf8), false);

// this tests a case where require_literal_leading_dot panicked.
assert_eq!(options.require_literal_leading_dot, true);
// ensure that we don't panic
assert_eq!(
glob_with_vec("i/qwe/nothing*", options),
Vec::<PathBuf>::new()
);
}
}
Loading