Skip to content
Browse files

sprintf() will throw an exception when was given named format twice.

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

assert_raise(ArgumentError) {sprintf("%<key><key2>s", { :key => "value", :key2 => "test" }) }

puts :ok
}}}

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@4947 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent 18c6303 commit 9031bde6907b089cf68631fb9dc1e53ac8c85947 @Watson1978 Watson1978 committed Nov 26, 2010
Showing with 5 additions and 0 deletions.
  1. +5 −0 sprintf.c
View
5 sprintf.c
@@ -449,6 +449,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
bool zero_flag = false;
bool width_flag = false;
bool precision_flag = false;
+ bool named_flag = false;
bool complete = false;
VALUE arg = 0;
long width = 0;
@@ -608,6 +609,10 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
case '<':
case '{':
+ if (named_flag) {
+ rb_raise(rb_eArgError, "named given twice");
+ }
+ named_flag = true;
SET_REF_TYPE(NAMED_REF);
arg = get_named_arg(format_str, format_len, &i,
GETNTHARG(0));

0 comments on commit 9031bde

Please sign in to comment.
Something went wrong with that request. Please try again.