Skip to content
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

Remove unsound quantifier reduction rules. #53

Merged

Conversation

jirkamarsik
Copy link
Contributor

Some of the quantifier reduction rules in oniguruma are invalid, leading to new regular expressions with different semantics. This PR removes two such reduction rules.

Here they are illustrated. If we introduce a capture group in between the two quantifiers, we prevent the quantifier reduction from triggering, leading to a different result.

irb(main):001:0> /(?:a+?)*/.match("aa")
=> #<MatchData "a">
irb(main):002:0> /(a+?)*/.match("aa")
=> #<MatchData "aa" 1:"a">
irb(main):003:0> /(?:a+?)+/.match("aa")
=> #<MatchData "a">
irb(main):004:0> /(a+?)+/.match("aa")
=> #<MatchData "aa" 1:"a">

I have reported the issue to MRI Ruby. This PR is a port of their PR.

https://bugs.ruby-lang.org/issues/17341
ruby/ruby#3808

Some of the quantifier reduction rules in oniguruma are invalid, leading to new
regular expressions with different semantics. This commit removes two such
reduction rules.

https://bugs.ruby-lang.org/issues/17341
ruby/ruby#3808
@jirkamarsik jirkamarsik force-pushed the remove-unsound-quantifier-reductions branch from 509a83d to f757501 Compare November 25, 2020 08:20
@headius
Copy link
Member

headius commented Dec 2, 2020

LGTM. Were tests added for this somewhere?

@headius headius added this to the 2.1.41 milestone Dec 2, 2020
@headius headius merged commit 51c97f0 into jruby:master Dec 2, 2020
@jirkamarsik
Copy link
Contributor Author

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

Successfully merging this pull request may close these issues.

None yet

2 participants