summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKenichi Kamiya <kachick1@gmail.com>2021-03-28 08:47:42 +0900
committerGitHub <noreply@github.com>2021-03-28 08:47:42 +0900
commit0a544c0c35f7445d69402d7c53d825384c728017 (patch)
tree12292326abb521d9e3096ac6e7b76314c6677b89 /test
parent95d9fe9538441eb57ee6752aa1c5088fc6608e34 (diff)
Fix segmentation fault when `Module#name` returns non string value [Bug #17754]
* Add test for NoMethodError#to_s does not segfault * Ensure no segfault even if Module#name is overridden
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4328 Merged-By: nobu <nobu@ruby-lang.org>
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_nomethod_error.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/ruby/test_nomethod_error.rb b/test/ruby/test_nomethod_error.rb
index 170a6c6c57..8b81052905 100644
--- a/test/ruby/test_nomethod_error.rb
+++ b/test/ruby/test_nomethod_error.rb
@@ -90,4 +90,20 @@ class TestNoMethodError < Test::Unit::TestCase
str.__send__(id)
end
end
+
+ def test_to_s
+ pre = Module.new do
+ def name
+ BasicObject.new
+ end
+ end
+ mod = Module.new
+ mod.singleton_class.prepend(pre)
+
+ err = assert_raise(NoMethodError) do
+ mod.this_method_does_not_exist
+ end
+
+ assert_match(/undefined method.+this_method_does_not_exist.+for.+Module/, err.to_s)
+ end
end