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

ruby-changes:43107

From: nobu <ko1@a...>
Date: Fri, 27 May 2016 17:09:51 +0900 (JST)
Subject: [ruby-changes:43107] nobu:r55181 (trunk): transcode.c: scrub in the given encoding

nobu	2016-05-27 17:09:46 +0900 (Fri, 27 May 2016)

  New Revision: 55181

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55181

  Log:
    transcode.c: scrub in the given encoding
    
    * transcode.c (str_transcode0): scrub in the given encoding when
      the source encoding is given, not in the encoding of the
      receiver.  [ruby-core:75732] [Bug #12431]

  Modified files:
    trunk/ChangeLog
    trunk/internal.h
    trunk/string.c
    trunk/test/ruby/test_transcode.rb
    trunk/transcode.c
Index: internal.h
===================================================================
--- internal.h	(revision 55180)
+++ internal.h	(revision 55181)
@@ -1356,6 +1356,7 @@ VALUE rb_str_locktmp_ensure(VALUE str, V https://github.com/ruby/ruby/blob/trunk/internal.h#L1356
 VALUE rb_external_str_with_enc(VALUE str, rb_encoding *eenc);
 VALUE rb_str_cat_conv_enc_opts(VALUE newstr, long ofs, const char *ptr, long len,
 			       rb_encoding *from, int ecflags, VALUE ecopts);
+VALUE rb_enc_str_scrub(rb_encoding *enc, VALUE str, VALUE repl);
 #endif
 #define STR_NOEMBED      FL_USER1
 #define STR_SHARED       FL_USER2 /* = ELTS_SHARED */
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 55180)
+++ ChangeLog	(revision 55181)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri May 27 17:09:44 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* transcode.c (str_transcode0): scrub in the given encoding when
+	  the source encoding is given, not in the encoding of the
+	  receiver.  [ruby-core:75732] [Bug #12431]
+
 Fri May 27 15:07:32 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* include/ruby/ruby.h (rb_scan_args): remove nul padding which
Index: string.c
===================================================================
--- string.c	(revision 55180)
+++ string.c	(revision 55181)
@@ -8927,8 +8927,13 @@ str_compat_and_valid(VALUE str, rb_encod https://github.com/ruby/ruby/blob/trunk/string.c#L8927
 VALUE
 rb_str_scrub(VALUE str, VALUE repl)
 {
+    return rb_enc_str_scrub(STR_ENC_GET(str), str, repl);
+}
+
+VALUE
+rb_enc_str_scrub(rb_encoding *enc, VALUE str, VALUE repl)
+{
     int cr = ENC_CODERANGE(str);
-    rb_encoding *enc;
     int encidx;
     VALUE buf = Qnil;
     const char *rep;
@@ -8938,7 +8943,6 @@ rb_str_scrub(VALUE str, VALUE repl) https://github.com/ruby/ruby/blob/trunk/string.c#L8943
     if (ENC_CODERANGE_CLEAN_P(cr))
 	return Qnil;
 
-    enc = STR_ENC_GET(str);
     if (!NIL_P(repl)) {
 	repl = str_compat_and_valid(repl, enc);
 	tainted = OBJ_TAINTED_RAW(repl);
Index: transcode.c
===================================================================
--- transcode.c	(revision 55180)
+++ transcode.c	(revision 55181)
@@ -2700,7 +2700,7 @@ str_transcode0(int argc, VALUE *argv, VA https://github.com/ruby/ruby/blob/trunk/transcode.c#L2700
 		if (!NIL_P(ecopts)) {
 		    rep = rb_hash_aref(ecopts, sym_replace);
 		}
-		dest = rb_str_scrub(str, rep);
+		dest = rb_enc_str_scrub(senc, str, rep);
 		if (NIL_P(dest)) dest = str;
 		*self = dest;
 		return dencidx;
Index: test/ruby/test_transcode.rb
===================================================================
--- test/ruby/test_transcode.rb	(revision 55180)
+++ test/ruby/test_transcode.rb	(revision 55181)
@@ -1213,6 +1213,9 @@ class TestTranscode < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_transcode.rb#L1213
   def test_invalid_replace_string
     assert_equal("a<x>A", "a\x80A".encode("us-ascii", "euc-jp", :invalid=>:replace, :replace=>"<x>"))
     assert_equal("a<x>A", "a\x80A".encode("us-ascii", "euc-jis-2004", :invalid=>:replace, :replace=>"<x>"))
+    s = "abcd\u{c1}"
+    r = s.b.encode("UTF-8", "UTF-8", invalid: :replace, replace: "\u{fffd}")
+    assert_equal(s, r)
   end
 
   def test_undef_replace

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

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