[前][次][番号順一覧][スレッド一覧]

ruby-changes:8338

From: nobu <ko1@a...>
Date: Tue, 21 Oct 2008 11:34:22 +0900 (JST)
Subject: [ruby-changes:8338] Ruby:r19866 (trunk): * ext/iconv/iconv.c (strip_glibc_option, map_charset): check if

nobu	2008-10-21 11:34:07 +0900 (Tue, 21 Oct 2008)

  New Revision: 19866

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19866

  Log:
    * ext/iconv/iconv.c (strip_glibc_option, map_charset): check if
      encoding is a string.  based on the patch by Hiroshi Moriyama at
      [ruby-dev:36811].
    
    * test/iconv/test_basic.rb (test_invalid_arguments): added tests.

  Modified files:
    trunk/ChangeLog
    trunk/ext/iconv/iconv.c
    trunk/test/iconv/test_basic.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 19865)
+++ ChangeLog	(revision 19866)
@@ -1,3 +1,11 @@
+Tue Oct 21 11:34:04 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* ext/iconv/iconv.c (strip_glibc_option, map_charset): check if
+	  encoding is a string.  based on the patch by Hiroshi Moriyama at
+	  [ruby-dev:36811].
+
+	* test/iconv/test_basic.rb (test_invalid_arguments): added tests.
+
 Tue Oct 21 10:40:37 2008  Nobuyoshi Nakada  <nobu@r...>
 
 	* io.c (rb_file_open_internal): should initialize fmode before using.
Index: ext/iconv/iconv.c
===================================================================
--- ext/iconv/iconv.c	(revision 19865)
+++ ext/iconv/iconv.c	(revision 19866)
@@ -144,9 +144,10 @@
 static VALUE
 strip_glibc_option(VALUE *code)
 {
-    VALUE val = *code;
+    VALUE val = StringValue(*code);
     const char *ptr = RSTRING_PTR(val), *pend = RSTRING_END(val);
     const char *slash = memchr(ptr, '/', pend - ptr);
+
     if (slash && slash < pend - 1 && slash[1] ==  '/') {
 	VALUE opt = rb_str_subseq(val, slash - ptr, pend - slash);
 	val = rb_str_subseq(val, 0, slash - ptr);
@@ -159,7 +160,7 @@
 static char *
 map_charset(VALUE *code)
 {
-    VALUE val = *code;
+    VALUE val = StringValue(*code);
 
     if (RHASH_SIZE(charset_map)) {
 	VALUE key = rb_funcall2(val, rb_intern("downcase"), 0, 0);
Index: test/iconv/test_basic.rb
===================================================================
--- test/iconv/test_basic.rb	(revision 19865)
+++ test/iconv/test_basic.rb	(revision 19866)
@@ -43,6 +43,13 @@
     assert_equal("#{SJIS_STR}\n"*2, output)
   end
 
+  def test_invalid_arguments
+    assert_raise(TypeError) { Iconv.new(nil, 'Shift_JIS') }
+    assert_raise(TypeError) { Iconv.new('Shift_JIS', nil) }
+    assert_raise(TypeError) { Iconv.open(nil, 'Shift_JIS') }
+    assert_raise(TypeError) { Iconv.open('Shift_JIS', nil) }
+  end
+
   def test_unknown_encoding
     assert_raise(Iconv::InvalidEncoding) { Iconv.iconv("utf-8", "X-UKNOWN", "heh") }
   end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]