[macruby-changes] [4938] MacRuby/trunk/sprintf.c
source_changes at macosforge.org
source_changes at macosforge.org
Mon Nov 22 19:31:31 PST 2010
Revision: 4938
http://trac.macosforge.org/projects/ruby/changeset/4938
Author: watson1978 at gmail.com
Date: 2010-11-22 19:31:28 -0800 (Mon, 22 Nov 2010)
Log Message:
-----------
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
}}}
Modified Paths:
--------------
MacRuby/trunk/sprintf.c
Modified: MacRuby/trunk/sprintf.c
===================================================================
--- MacRuby/trunk/sprintf.c 2010-11-23 03:26:28 UTC (rev 4937)
+++ MacRuby/trunk/sprintf.c 2010-11-23 03:31:28 UTC (rev 4938)
@@ -488,6 +488,9 @@
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 @@
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)));
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101122/22b49cd6/attachment.html>
More information about the macruby-changes
mailing list