ruby-changes:45229
From: nobu <ko1@a...>
Date: Wed, 11 Jan 2017 10:03:46 +0900 (JST)
Subject: [ruby-changes:45229] nobu:r57302 (trunk): string.c: block for scrub with ASCII-incompatible
nobu 2017-01-11 10:03:37 +0900 (Wed, 11 Jan 2017) New Revision: 57302 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57302 Log: string.c: block for scrub with ASCII-incompatible * string.c (rb_enc_str_scrub): honor the given block with ASCII-incompatible encoding. [ruby-core:79039] [Bug #13120] Modified files: trunk/string.c trunk/test/ruby/test_m17n.rb Index: string.c =================================================================== --- string.c (revision 57301) +++ string.c (revision 57302) @@ -9345,7 +9345,11 @@ rb_enc_str_scrub(rb_encoding *enc, VALUE https://github.com/ruby/ruby/blob/trunk/string.c#L9345 const char *e = RSTRING_END(str); const char *p1 = p; long mbminlen = rb_enc_mbminlen(enc); - if (!NIL_P(repl)) { + if (rb_block_given_p()) { + rep = NULL; + replen = 0; + } + else if (!NIL_P(repl)) { rep = RSTRING_PTR(repl); replen = RSTRING_LEN(repl); } Index: test/ruby/test_m17n.rb =================================================================== --- test/ruby/test_m17n.rb (revision 57301) +++ test/ruby/test_m17n.rb (revision 57302) @@ -1640,6 +1640,11 @@ class TestM17N < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_m17n.rb#L1640 assert_equal("\uFFFD".encode("UTF-32LE"), "\xff".force_encoding(Encoding::UTF_32LE). scrub) + c = nil + assert_equal("?".encode(Encoding::UTF_16LE), + "\x00\xD8".force_encoding(Encoding::UTF_16LE). + scrub {|e| c = e; "?".encode(Encoding::UTF_16LE)}) + assert_equal("\x00\xD8".force_encoding(Encoding::UTF_16LE), c) end def test_scrub_dummy_encoding -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/