Skip to content

regex and regex_lite disagree on lazy empty matches #1357

Description

@orlp

What version of regex are you using?

regex == 1.12.3
regex_lite == 0.1.9

Describe the bug at a high level.

An empty lazy (??) match has different behavior between the two engines.

What are the steps to reproduce the behavior?

let pattern = "b??a|b??a?";
let haystack = "bba";
dbg!(regex::Regex::new(pattern).unwrap().find_iter(haystack).collect::<Vec<_>>());
dbg!(regex_lite::Regex::new(pattern).unwrap().find_iter(haystack).collect::<Vec<_>>());

What is the actual behavior?

[src/main.rs:8:5] regex::Regex::new(pattern).unwrap().find_iter(haystack).collect::<Vec<_>>() = [
    Match {
        start: 0,
        end: 0,
        string: "",
    },
    Match {
        start: 1,
        end: 1,
        string: "",
    },
    Match {
        start: 2,
        end: 3,
        string: "a",
    },
]
[src/main.rs:9:5] regex_lite::Regex::new(pattern).unwrap().find_iter(haystack).collect::<Vec<_>>() = [
    Match {
        start: 0,
        end: 0,
        string: "",
    },
    Match {
        start: 1,
        end: 3,
        string: "ba",
    },
]

What is the expected behavior?

I don't know, but the same behavior for both. I found it through fuzzing.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions