summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-07-15 20:45:55 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-07-15 20:45:55 +0000
commit192c936e2317286fa428a76a4018c9082d11c828 (patch)
tree3e3545e5eb7871c1aa8635b6861d36b2ba3750f0 /test
parent66e1be60c39e3ab96fc7de01fb950cac9b5bc700 (diff)
* sprintf.c (rb_f_sprintf): more checks for format argument.
[ruby-core:11569], [ruby-core:11570], [ruby-core:11571], [ruby-core:11573] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12803 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_sprintf.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/ruby/test_sprintf.rb b/test/ruby/test_sprintf.rb
index c72eadb218..5e0b763e99 100644
--- a/test/ruby/test_sprintf.rb
+++ b/test/ruby/test_sprintf.rb
@@ -138,4 +138,37 @@ class TestSprintf < Test::Unit::TestCase
assert_equal("-Inf ", sprintf("%- 08f", -inf))
assert_equal("-0000Inf", sprintf("%+ 08f", -inf))
end
+
+ def test_invalid
+ # [ruby-core:11569]
+
+ # Star precision before star width:
+ assert_raise(ArgumentError) {sprintf("%.**d", 5, 10, 1)}
+
+ # Precision before flags and width:
+ assert_raise(ArgumentError) {sprintf("%.5+05d", 5)}
+ assert_raise(ArgumentError) {sprintf("%.5 5d", 5)}
+
+ # Overriding a star width with a numeric one:
+ assert_raise(ArgumentError) {sprintf("%*1s", 5, 1)}
+
+ # Width before flags:
+ assert_raise(ArgumentError) {sprintf("%5+0d", 1)}
+ assert_raise(ArgumentError) {sprintf("%5 0d", 1)}
+
+ # Specifying width multiple times:
+ assert_raise(ArgumentError) {sprintf("%50+30+20+10+5d", 5)}
+ assert_raise(ArgumentError) {sprintf("%50 30 20 10 5d", 5)}
+
+ # [ruby-core:11570]
+ # Specifying the precision multiple times with negative star arguments:
+ assert_raise(ArgumentError) {sprintf("%.*.*.*.*f", -1, -1, -1, 5, 1)}
+
+ # [ruby-core:11571]
+ # Null bytes after percent signs are removed:
+ assert_equal("%\0x hello", sprintf("%\0x hello"))
+
+ # [ruby-core:11573]
+ assert_raise(ArgumentError) {sprintf("%.25555555555555555555555555555555555555s", "hello")}
+ end
end