diff options
author | Jeremy Evans <code@jeremyevans.net> | 2020-11-23 14:40:59 -0800 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2020-12-02 18:42:02 +0100 |
commit | 9e73177d5362c1986814f411961b712967dc5f97 (patch) | |
tree | f0ddbddc3e24423cd39128c3bdebf07d7e6608d1 /test | |
parent | 7546be2ca0de45bcc2a72d9b4ae0cd44a1322031 (diff) | |
download | ruby-9e73177d5362c1986814f411961b712967dc5f97.tar.gz |
Do not reduce quantifiers if it affects which text will be matched
Quantifier reduction when using +?)* and +?)+ should not be done
as it affects which text will be matched.
This removes the need for the RQ_PQ_Q ReduceType, so remove the
enum entry and related switch case.
Test that these are the only two patterns affected by testing all
quantifier reduction tuples for both the captured and uncaptured
cases and making sure the matched text is the same for both.
Fixes [Bug #17341]
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_regexp.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index e124fc7952..e9d1fc30d4 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -1196,6 +1196,20 @@ class TestRegexp < Test::Unit::TestCase } end + def test_quantifier_reduction + assert_equal('aa', eval('/(a+?)*/').match('aa')[0]) + assert_equal('aa', eval('/(?:a+?)*/').match('aa')[0]) + + quantifiers = %w'? * + ?? *? +?' + quantifiers.each do |q1| + quantifiers.each do |q2| + r1 = eval("/(a#{q1})#{q2}/").match('aa')[0] + r2 = eval("/(?:a#{q1})#{q2}/").match('aa')[0] + assert_equal(r1, r2) + end + end + end + def test_once pr1 = proc{|i| /#{i}/o} assert_equal(/0/, pr1.call(0)) |