Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

globset: allow building globs from OS strings #1250

Open
BurntSushi opened this issue Apr 16, 2019 · 0 comments
Open

globset: allow building globs from OS strings #1250

BurntSushi opened this issue Apr 16, 2019 · 0 comments
Labels
enhancement An enhancement to the functionality of the software.

Comments

@BurntSushi
Copy link
Owner

Initially reported here: rust-lang/glob#78

While globset can match on arbitrary OS strings, it cannot accept an arbitrary OS string as a glob. The link above gives an example. Here it is in code form (which currently prints false):

use std::error::Error;
use std::ffi::OsStr;
use std::os::unix::ffi::OsStrExt;

use globset::Glob;

fn main() -> Result<(), Box<dyn Error>> {
    let glob = Glob::new(r"d\xE9cembre 2018 - *.jpg")?;
    let matcher = glob.compile_matcher();
    let filename = OsStr::from_bytes(b"d\xE9cembre 2018 - foo.jpg");
    println!("{:?}", matcher.is_match(filename));
    Ok(())
}

To be clear, this particular program shouldn't succeed because a UTF-8 string is given to Glob::new. But there should be a way to, for example, call Glob::new(some_os_str). On Unix, that OS string can be arbitrary bytes.

(The globset crate is due for an API refresh and likely a rewrite of its internal parser anyway. This should be fairly easy to support.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement to the functionality of the software.
Projects
None yet
Development

No branches or pull requests

1 participant