-
Notifications
You must be signed in to change notification settings - Fork 443
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
Fix panics with whitespace in extended mode by being more strict #354
Fix panics with whitespace in extended mode by being more strict #354
Conversation
Instead of ignoring space in all the bump/peek methods (as proposed in pull request rust-lang#349), have an explicit `ignore_space` method that can be used in places where space/comments should be allowed. This makes parsing a bit stricter than before as well.
@@ -2424,6 +2489,14 @@ mod tests { | |||
])); | |||
} | |||
|
|||
#[test] | |||
fn ignore_space_escape_space() { | |||
assert_eq!(p(r"(?x)a\ # hi there"), Expr::Concat(vec![ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allowing to escape whitespace is in line with what PCRE2 does, see here: http://www.pcre.org/current/doc/html/pcre2pattern.html#SEC5
An escaping backslash can be used to include a white space or # character as part of the pattern.
And it seems less surprising than allowing \ d
or the following to mean digits:
r"(?x)\ # comment
d"
@robinst Thanks so much for working on this! This behavior is indeed a bit more in line with what I'd expect. I will say though that doing it this way leads to a lot more implementation complexity. :-( I'm not sure I can immediately think of a better way though.
Hmmm, yes, I'll need to think about this. I'm a bit distracted at the moment. |
FWIW, fancy-regex's parser does it the same way as I discovered recently, see the calls to |
@robinst Sorry for taking so long to get around this. For the most part, I've avoid this because I've been internally waffling over this, but that's silly to do. Some thoughts:
Thanks so much for finding and fixing this bug. It is much appreciated! |
@bors r+ |
📌 Commit 6f32d2f has been approved by |
…e-strict, r=BurntSushi Fix panics with whitespace in extended mode by being more strict Instead of ignoring space in all the bump/peek methods (as proposed in pull request #349), have an explicit `ignore_space` method that can be used in places where space/comments should be allowed. This makes parsing a bit stricter than before as well.
☀️ Test successful - status-appveyor, status-travis |
Instead of ignoring space in all the bump/peek methods (as proposed in
pull request #349), have an explicit
ignore_space
method that can beused in places where space/comments should be allowed.
This makes parsing a bit stricter than before as well.