Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

sprintf("%c") will throw an exception when does not pass one character.

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

assert_raise(ArgumentError) { sprintf("%c", "cc") }

puts :ok
}}}

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@5015 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
commit abe5fa783eb08e1c770d0d3399d16947ad19edab 1 parent d8ba919
@Watson1978 Watson1978 authored
Showing with 3 additions and 1 deletion.
  1. +3 −1 sprintf.c
View
4 sprintf.c
@@ -669,7 +669,9 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
case 'C':
GET_ARG();
if (TYPE(arg) == T_STRING) {
- arg = rb_str_substr(arg, 0, 1);
+ if(RSTRING_LEN(arg) != 1) {
+ rb_raise(rb_eArgError, "%%c requires a character");
+ }
}
else {
long num = NUM2LONG(arg);

0 comments on commit abe5fa7

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