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

ruby-changes:45230

From: nobu <ko1@a...>
Date: Wed, 11 Jan 2017 11:18:50 +0900 (JST)
Subject: [ruby-changes:45230] nobu:r57303 (trunk): string.c: yield invalid part

nobu	2017-01-11 11:18:45 +0900 (Wed, 11 Jan 2017)

  New Revision: 57303

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

  Log:
    string.c: yield invalid part
    
    * string.c (rb_enc_str_scrub): yield the invalid part only with
      ASCII-incompatible.  [ruby-core:79039] [Bug #13120]

  Modified files:
    trunk/string.c
    trunk/test/ruby/test_m17n.rb
Index: string.c
===================================================================
--- string.c	(revision 57302)
+++ string.c	(revision 57303)
@@ -9400,7 +9400,7 @@ rb_enc_str_scrub(rb_encoding *enc, VALUE https://github.com/ruby/ruby/blob/trunk/string.c#L9400
 		    rb_str_buf_cat(buf, rep, replen);
 		}
 		else {
-		    repl = rb_yield(rb_enc_str_new(p, e-p, enc));
+		    repl = rb_yield(rb_enc_str_new(p, clen, enc));
 		    repl = str_compat_and_valid(repl, enc);
 		    tainted |= OBJ_TAINTED_RAW(repl);
 		    rb_str_buf_cat(buf, RSTRING_PTR(repl), RSTRING_LEN(repl));
Index: test/ruby/test_m17n.rb
===================================================================
--- test/ruby/test_m17n.rb	(revision 57302)
+++ test/ruby/test_m17n.rb	(revision 57303)
@@ -1623,7 +1623,7 @@ class TestM17N < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_m17n.rb#L1623
     assert_raise(ArgumentError){ u("\xE3\x81\x82\xE3\x81\x82\xE3\x81").scrub{u("\x81")} }
     assert_equal(e("\xA4\xA2\xA2\xAE"), e("\xA4\xA2\xA4").scrub{e("\xA2\xAE")})
 
-    assert_equal(u("\x81"), u("a\x81").scrub {|c| break c})
+    assert_equal(u("\x81"), u("a\x81c").scrub {|c| break c})
     assert_raise(ArgumentError) {u("a\x81").scrub {|c| c}}
   end
 
@@ -1641,8 +1641,8 @@ class TestM17N < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_m17n.rb#L1641
                  "\xff".force_encoding(Encoding::UTF_32LE).
                  scrub)
     c = nil
-    assert_equal("?".encode(Encoding::UTF_16LE),
-                 "\x00\xD8".force_encoding(Encoding::UTF_16LE).
+    assert_equal("?\u3042".encode(Encoding::UTF_16LE),
+                 "\x00\xD8\x42\x30".force_encoding(Encoding::UTF_16LE).
                    scrub {|e| c = e; "?".encode(Encoding::UTF_16LE)})
     assert_equal("\x00\xD8".force_encoding(Encoding::UTF_16LE), c)
   end

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

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