Raise ArgumentError if sprintf format string ends with %

* Add tests and specs. See ruby/spec#401.
  Patch by Yuta Iwama and Shintaro Morikawa.
  [ruby-core:80153] [Bug #13315] [Fix GH-1560]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58890 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2017-05-25 15:33:28 +00:00
parent e779eee98b
commit fd8df3ab3d
3 changed files with 26 additions and 4 deletions

View file

@ -424,6 +424,16 @@ class TestSprintf < Test::Unit::TestCase
assert_equal("%" * BSIZ, sprintf("%%" * BSIZ))
end
def test_percent_sign_at_end
assert_raise_with_message(ArgumentError, "incomplete format specifier") do
sprintf("%")
end
assert_raise_with_message(ArgumentError, "incomplete format specifier") do
sprintf("abc%")
end
end
def test_rb_sprintf
assert_match(/^#<TestSprintf::T012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789:0x[0-9a-f]+>$/,
T012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789.new.inspect)