[macruby-changes] [4947] MacRuby/trunk/sprintf.c

source_changes at macosforge.org source_changes at macosforge.org
Thu Nov 25 18:36:16 PST 2010


Revision: 4947
          http://trac.macosforge.org/projects/ruby/changeset/4947
Author:   watson1978 at gmail.com
Date:     2010-11-25 18:36:11 -0800 (Thu, 25 Nov 2010)
Log Message:
-----------
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
}}}

Modified Paths:
--------------
    MacRuby/trunk/sprintf.c

Modified: MacRuby/trunk/sprintf.c
===================================================================
--- MacRuby/trunk/sprintf.c	2010-11-26 01:50:19 UTC (rev 4946)
+++ MacRuby/trunk/sprintf.c	2010-11-26 02:36:11 UTC (rev 4947)
@@ -449,6 +449,7 @@
 	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 @@
 
 		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));
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101125/f5579871/attachment.html>


More information about the macruby-changes mailing list