meh / rust-abp-filter

Rust ABP filter parser.
1 stars 1 forks source link

Last verbatim #2

Open utvk opened 8 years ago

utvk commented 8 years ago

Hi I played a little with this cool code for some testing and learning rust and noticed an issue that I have tried to fix but given up on.

It doesn't seem to handle the last verbatime if multiple. e.g. a rule like this "google.com|" or "google.com/*". They will just fail as malformed because the last verbatim (Anchor / Wildcard) is not parsed properly.

Any idea how to get this test to run? Also wonder if you are planning to add code for doing rules matching as well?? :-D

    assert_eq!(super::matchers(b"|google.com|"), Done(&b""[..], vec![vec![
        Matcher::Anchor, Matcher::Verbatim("google.com".to_owned()),
        Matcher::Anchor]]));
meh commented 8 years ago

Yeah, I was working on the matching stuff.

I see the problem, it's either a nom bug or something I'm doing wrong, basically it's trying to complete the || matching, but it fails so it returns Incomplete.

meh commented 8 years ago

@geal any ideas?

This is the culprit.

Geal commented 8 years ago

This is tricky, because two cases have a common prefix. The case matching || is failing with Incomplete because it expects two characters, but if we put it after the case matching just |, that one will absorb the input all the time.

There's one way to fix it, if you know you won't consume partial input (ex: when you can have the full file in memory), by wrapping line 54 with the complete! combinator, which transforms a Incomplete in an Error. That way, if it receives a simple |, the second case will take it, as expected.