-
Notifications
You must be signed in to change notification settings - Fork 819
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
many_m_n can succeed when min > max #1333
Comments
thanks for the report, it will be fixed in nom 7 with ab42ced |
@Geal looking at ab42ced it looks like the Additionally a nom error might also never reach the user since certain parser such as alt() might swallow it. This could lead to unintended behaviour since the parser runs successfully but doesnt produce the desired output. Since no error is reported finding the source of such an issue would be potentially difficult and time consuming. |
Parsers should never panic, and since parsers can be created dynamically from the output of other parsers, parser creation should not panic either (that could result in easy DoS attacks by messing with the format). |
@cenodis it's not like all parameters to parsers are always hardcoded; I made this issue because I myself wrote a parser where min and max were the result of some computations, and it indeed made sense that, when those results happen to lead to min > max, parsing silently fails. If this function wasn't It's also consistent with e.g. fn main() {
dbg!((4..=2).is_empty()); // => true
dbg!((4..=2).contains(&3)); // => false
} |
@Geal I wasnt aware parsers should never panic, my apologies. However, I would like to argue for As already stated The fact that the parser fails silently is also not really obvious from the outside. After all the function is called I dont disagree that there are cases where having it fail silently is useful. But that should not be part of the
Side note: I actually thought This is also more in line with the parser combinator principle (Combining multiple parsers with simple, obvious behaviour instead of having one parser with complex behaviour). I dont see much practical reason to be consistent with the Edit: |
fix released in nom 7: https://crates.io/crates/nom/7.0.0 |
I do not think the solution here is good, it's should be outside the closure and in my opinion panic on such case or return a Actually why not take a |
as already stated by Geal, parser creation should never fail. A panic is therefore unnaceptable.
To my knowledge In #1356 I suggested replacing the |
Indeed, one would need something like |
No but https://doc.rust-lang.org/core/ops/trait.RangeBounds.html#method.contains would corretly report false: fn main() {
let r = 42..21;
assert_eq!(r.contains(&30), false);
} |
What does that have to do with anything? max > min is invalid for this parser and Rangebound does not prevent such a range from being constructed. |
that would solve the original problem, but that would not allow your request to make it an hard error. Well yes That could depend on how you use it |
I think |
The following code:
will succeed, consuming two
'a'
:While it is unlikely that someone would hardcode a minimum value greater than a maximum value, they can be the result of more complex code, and a call to
many_m_n
in such conditions should probably systematically fail (as the constraint of parsing something at least min but at most max times would be impossible to satisfy).Have a nice day
The text was updated successfully, but these errors were encountered: