Permalink
Browse files

fixed the bug of sprintf() within "%<named>" format

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

assert_equal("value", sprintf("%<key>s", :key => "value"))
assert_equal("12345", sprintf("%<test>d", :test=> 12345))

puts :ok
}}}

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@4946 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent 0198d3b commit 18c6303e06ee39913a7efd7d15ff2b718bbbd346 @Watson1978 Watson1978 committed Nov 26, 2010
Showing with 3 additions and 1 deletion.
  1. +3 −1 sprintf.c
View
@@ -393,14 +393,16 @@ get_named_arg(UChar *format_str, long format_len, long *i, VALUE hash)
}
UChar closing = format_str[(*i)++] + 2;
UChar *str_ptr = &format_str[*i];
+ long length = 0;
while (*i < format_len && format_str[*i] != closing) {
(*i)++;
+ length++;
}
if (*i == format_len) {
rb_raise(rb_eArgError,
"malformed name - unmatched parenthesis");
}
- VALUE substr = rb_unicode_str_new(str_ptr, str_ptr - format_str);
+ VALUE substr = rb_unicode_str_new(str_ptr, (size_t)length);
hash = rb_hash_aref(hash, ID2SYM(rb_intern_str(substr)));
return hash;
}

0 comments on commit 18c6303

Please sign in to comment.