summaryrefslogtreecommitdiff
path: root/test/ruby/test_regexp.rb
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2022-03-24 16:59:11 +0900
committerYusuke Endoh <mame@ruby-lang.org>2022-03-30 16:50:46 +0900
commitffc3b37f969a779f93b8f8a5b3591b4ef7de1538 (patch)
tree25b2d942e8eb2c4a73043773edfcfd6c0d709155 /test/ruby/test_regexp.rb
parent23530d68cb04aed9c2f59a050523b0193ee2d0c1 (diff)
re.c: Add Regexp.timeout= and Regexp.timeout
[Feature #17837]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5703
Diffstat (limited to 'test/ruby/test_regexp.rb')
-rw-r--r--test/ruby/test_regexp.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb
index 94098a850d..7bcddc6e07 100644
--- a/test/ruby/test_regexp.rb
+++ b/test/ruby/test_regexp.rb
@@ -1457,4 +1457,21 @@ class TestRegexp < Test::Unit::TestCase
}
assert_empty(errs, msg)
end
+
+ def test_s_timeout
+ assert_separately([], "#{<<-"begin;"}\n#{<<-"end;"}")
+ begin;
+ Regexp.timeout = 0.2
+ assert_equal(0.2, Regexp.timeout)
+
+ t = Time.now
+ assert_raise_with_message(RuntimeError, "regexp match timeout") do
+ # A typical ReDoS case
+ /^(a*)*$/ =~ "a" * 1000000 + "x"
+ end
+ t = Time.now - t
+
+ assert_in_delta(0.2, t, 0.1)
+ end;
+ end
end