Permalink
Browse files

String#% will throw an ArgumentError when was given "*0$" format.

Test Script:
{{{
require 'test/unit/assertions.rb'
include Test::Unit::Assertions

assert_raise(ArgumentError){ "%*0$s" % [5, "x"] }
assert_raise(ArgumentError){ "%*1$.*0$1$s" % [1, 2, 3] }

puts :ok
}}}

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@4938 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent da97b83 commit c9853df53210acab8481702e114bba3586d7eef1 @Watson1978 Watson1978 committed Nov 23, 2010
Showing with 6 additions and 0 deletions.
  1. +6 −0 sprintf.c
View
@@ -488,6 +488,9 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
j++;
}
else if (format_str[pos] == '$') {
+ if (num == 0) {
+ rb_raise(rb_eArgError, "invalid absolute argument");
+ }
SET_REF_TYPE(ABS_REF);
width = NUM2LONG(rb_Integer(GETNTHARG(num - 1)));
i = pos;
@@ -574,6 +577,9 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
j++;
}
else if (format_str[pos] == '$') {
+ if (num == 0) {
+ rb_raise(rb_eArgError, "invalid absolute argument");
+ }
SET_REF_TYPE(ABS_REF);
precision = NUM2LONG(rb_Integer(GETNTHARG(
num - 1)));

0 comments on commit c9853df

Please sign in to comment.