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

ruby-changes:7795

From: akr <ko1@a...>
Date: Sat, 13 Sep 2008 03:46:06 +0900 (JST)
Subject: [ruby-changes:7795] Ruby:r19316 (trunk): * transcode.c (rb_econv_prepare_opts): raise ArgumentError if

akr	2008-09-13 03:45:44 +0900 (Sat, 13 Sep 2008)

  New Revision: 19316

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

  Log:
    * transcode.c (rb_econv_prepare_opts): raise ArgumentError if
      a broken string is specified as a replacement.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_econv.rb
    trunk/transcode.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 19315)
+++ ChangeLog	(revision 19316)
@@ -1,3 +1,8 @@
+Sat Sep 13 03:44:52 2008  Tanaka Akira  <akr@f...>
+
+	* transcode.c (rb_econv_prepare_opts): raise ArgumentError if
+	  a broken string is specified as a replacement.
+
 Sat Sep 13 03:31:05 2008  Tanaka Akira  <akr@f...>
 
 	* iseq.c (iseq_s_compile_file): use rb_file_open_str.
Index: test/ruby/test_econv.rb
===================================================================
--- test/ruby/test_econv.rb	(revision 19315)
+++ test/ruby/test_econv.rb	(revision 19316)
@@ -871,4 +871,11 @@
     assert_equal([[iso88591,utf8], "universal_newline", [utf8,utf32be]],
                  Encoding::Converter.search_convpath("ISO-8859-1", "UTF-32BE", universal_newline: true))
   end
+
+  def test_invalid_replace
+    assert_raise(ArgumentError) {
+      broken = "\x80".force_encoding("euc-jp")
+      "".encode("euc-jp", :undef => :replace, :replace => broken)
+    }
+  end
 end
Index: transcode.c
===================================================================
--- transcode.c	(revision 19315)
+++ transcode.c	(revision 19316)
@@ -2254,7 +2254,6 @@
     }
     else if (v==sym_replace) {
         ecflags |= ECONV_INVALID_REPLACE;
-        v = rb_hash_aref(opt, sym_replace);
     }
     else {
         rb_raise(rb_eArgError, "unknown value for invalid character option");
@@ -2315,6 +2314,12 @@
         VALUE v = rb_hash_aref(opthash, sym_replace);
         if (!NIL_P(v)) {
             StringValue(v);
+            if (rb_enc_str_coderange(v) == ENC_CODERANGE_BROKEN) {
+                VALUE dumped = rb_str_dump(v);
+                rb_raise(rb_eArgError, "replacement string is broken: %s as %s",
+                        StringValueCStr(dumped),
+                        rb_enc_name(rb_enc_get(v)));
+            }
             v = rb_str_new_frozen(v);
             newhash = rb_hash_new();
             rb_hash_aset(newhash, sym_replace, v);

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

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