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

RegexSet doesn't respect the ^ anchor #358

Closed
kalekseev opened this issue May 1, 2017 · 1 comment · Fixed by #370
Closed

RegexSet doesn't respect the ^ anchor #358

kalekseev opened this issue May 1, 2017 · 1 comment · Fixed by #370
Labels

Comments

@kalekseev
Copy link

Compiled with regex 0.2.1

    println!("{:?}", RegexSet::new(&[r"^rooted$"]).unwrap().matches("notrooted"));
    println!("{:?}", RegexSet::new(&[r"^rooted$", r".log$"]).unwrap().matches("notrooted"));
    println!("{:?}", RegexSet::new(&[r"^rooted$", r"\.log$"]).unwrap().matches("notrooted"));
    println!("{:?}", RegexSet::new(&[r"^rooted$", r"\.log$"]).unwrap().matches("notrootedend"));

Output:

SetMatches { matched_any: false, matches: [false] }
SetMatches { matched_any: false, matches: [false, false] }
SetMatches { matched_any: true, matches: [true, false] } 
SetMatches { matched_any: false, matches: [false, false] }
@kalekseev kalekseev changed the title RegexSet don't respect the ^ anchor RegexSet doesn't respect the ^ anchor May 1, 2017
BurntSushi added a commit to BurntSushi/regex that referenced this issue May 20, 2017
When combining multiple regexes in a set where some are anchored and
others aren't, it's possible to wind up in a situation where prefix
scanning is used. This is bad, because it can lead to some of the
anchored regexes matching where they shouldn't be allowed to match.
As a result, we disable all literal optimizations for regex sets if
*any* regex in the set is anchored.

Fixes rust-lang#358
@BurntSushi BurntSushi added the bug label May 20, 2017
@BurntSushi
Copy link
Member

This is a literal optimization bug.

bors added a commit that referenced this issue May 20, 2017
RegexSet: fix literal optimization bug

When combining multiple regexes in a set where some are anchored and
others aren't, it's possible to wind up in a situation where prefix
scanning is used. This is bad, because it can lead to some of the
anchored regexes matching where they shouldn't be allowed to match.
As a result, we disable all literal optimizations for regex sets if
*any* regex in the set is anchored.

Fixes #358
@bors bors closed this as completed in #370 May 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants