Skip to content

RegexSet matched_any() yields true, but iter() returns no indexes #187

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

Closed
dprien opened this issue Mar 15, 2016 · 1 comment
Closed

RegexSet matched_any() yields true, but iter() returns no indexes #187

dprien opened this issue Mar 15, 2016 · 1 comment
Labels

Comments

@dprien
Copy link

dprien commented Mar 15, 2016

Unfortunately, it looks like 3fb34e2 (the fix for #186) introduced a bug in RegexSet:

extern crate regex;
fn main() {
    let set = regex::RegexSet::new(&[r"^\s+", r"^[a-z]+"]).unwrap();

    let r1 = set.matches("lorem ipsum dolor");
    assert!(r1.matched_any());
    println!("{:?}, {:?}", r1, r1.iter().collect::<Vec<_>>());

    let r2 = set.matches("ipsum dolor");
    assert!(r2.matched_any());
    println!("{:?}, {:?}", r2, r2.iter().collect::<Vec<_>>());
}

Output:

SetMatches { matched_any: true, matches: [false, true] }, [1]
SetMatches { matched_any: true, matches: [false, false] }, []

That is, the second call to matches claims a match has been found, but iter() does not return any indexes.
Curiously, if you omit the first matches call, the second call works as expected, yielding SetMatches { matched_any: true, matches: [false, true] }, [1].

@BurntSushi BurntSushi added the bug label Mar 15, 2016
@BurntSushi
Copy link
Member

Yup, dammit. My approach to fixing #186 was silly. (All of the matching engines have interior mutable state, which is the fundamental reason why removing set.matches can cause r2.matched_any to work.)

Since this impacts correctness, I've yanked 0.1.57. I'll try to straighten this out today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants