summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-sprintf/test/sprintf.rb
diff options
context:
space:
mode:
authorBouke van der Bijl <[email protected]>2016-11-23 15:18:52 -0500
committerBouke van der Bijl <[email protected]>2016-11-23 15:18:52 -0500
commit9bf1c0e1dc09d9aa577554d58d91f3889a77b918 (patch)
tree993b067c7f5675a8b8169d5c1ed860f42ae7b515 /mrbgems/mruby-sprintf/test/sprintf.rb
parent669bbc70b0553b68483c8d7eff8c31a602f283e9 (diff)
downloadmruby-9bf1c0e1dc09d9aa577554d58d91f3889a77b918.tar.gz
mruby-9bf1c0e1dc09d9aa577554d58d91f3889a77b918.zip
Fix segfault when Fixnum#chr doesn't return a string
Diffstat (limited to 'mrbgems/mruby-sprintf/test/sprintf.rb')
-rw-r--r--mrbgems/mruby-sprintf/test/sprintf.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/mrbgems/mruby-sprintf/test/sprintf.rb b/mrbgems/mruby-sprintf/test/sprintf.rb
index 478581a49..ccbd95d51 100644
--- a/mrbgems/mruby-sprintf/test/sprintf.rb
+++ b/mrbgems/mruby-sprintf/test/sprintf.rb
@@ -7,3 +7,26 @@ assert('String#%') do
assert_equal "123 < 456", "%{num} < %<str>s" % { num: 123, str: "456" }
assert_equal 15, ("%b" % (1<<14)).size
end
+
+assert("String#% with invalid chr") do
+ begin
+ class Fixnum
+ alias_method :chr_, :chr if method_defined?(:chr)
+
+ def chr
+ nil
+ end
+ end
+
+ assert_raise TypeError do
+ "%c" % 0
+ end
+ ensure
+ class Fixnum
+ if method_defined?(:chr_)
+ alias_method :chr, :chr_
+ remove_method :chr_
+ end
+ end
+ end
+end