ruby-changes:46020
From: usa <ko1@a...>
Date: Sun, 26 Mar 2017 00:36:06 +0900 (JST)
Subject: [ruby-changes:46020] usa:r58091 (ruby_2_2): merge revision(s) 57302, 57303, 57304: [Backport #13119]
usa 2017-03-26 00:36:01 +0900 (Sun, 26 Mar 2017) New Revision: 58091 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58091 Log: merge revision(s) 57302,57303,57304: [Backport #13119] 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] string.c: yield invalid part * string.c (rb_enc_str_scrub): yield the invalid part only with ASCII-incompatible. [ruby-core:79039] [Bug #13120] string.c: replacement and block * string.c (rb_enc_str_scrub): only one of replacement and block is allowed. [ruby-core:79038] [Bug #13119] Modified directories: branches/ruby_2_2/ Modified files: branches/ruby_2_2/string.c branches/ruby_2_2/test/ruby/test_m17n.rb branches/ruby_2_2/version.h Index: ruby_2_2/version.h =================================================================== --- ruby_2_2/version.h (revision 58090) +++ ruby_2_2/version.h (revision 58091) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1 #define RUBY_VERSION "2.2.7" #define RUBY_RELEASE_DATE "2017-03-26" -#define RUBY_PATCHLEVEL 423 +#define RUBY_PATCHLEVEL 424 #define RUBY_RELEASE_YEAR 2017 #define RUBY_RELEASE_MONTH 3 Index: ruby_2_2/test/ruby/test_m17n.rb =================================================================== --- ruby_2_2/test/ruby/test_m17n.rb (revision 58090) +++ ruby_2_2/test/ruby/test_m17n.rb (revision 58091) @@ -1592,8 +1592,9 @@ class TestM17N < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/ruby/test_m17n.rb#L1592 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}} + assert_raise(ArgumentError) {u("a").scrub("?") {|c| c}} end def test_scrub_widechar @@ -1609,6 +1610,12 @@ class TestM17N < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/ruby/test_m17n.rb#L1610 assert_equal("\uFFFD".encode("UTF-32LE"), "\xff".force_encoding(Encoding::UTF_32LE). scrub) + c = nil + 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) + assert_raise(ArgumentError) {"\uFFFD\u3042".encode("UTF-16BE").scrub("") {}} end def test_scrub_bang Index: ruby_2_2/string.c =================================================================== --- ruby_2_2/string.c (revision 58090) +++ ruby_2_2/string.c (revision 58091) @@ -8345,9 +8345,15 @@ rb_enc_str_scrub(rb_encoding *enc, VALUE https://github.com/ruby/ruby/blob/trunk/ruby_2_2/string.c#L8345 int encidx; VALUE buf = Qnil; const char *rep; - long replen; + long replen = -1; int tainted = 0; + if (rb_block_given_p()) { + if (!NIL_P(repl)) + rb_raise(rb_eArgError, "both of block and replacement given"); + replen = 0; + } + if (cr == ENC_CODERANGE_7BIT || cr == ENC_CODERANGE_VALID) return Qnil; @@ -8371,9 +8377,8 @@ rb_enc_str_scrub(rb_encoding *enc, VALUE https://github.com/ruby/ruby/blob/trunk/ruby_2_2/string.c#L8377 const char *e = RSTRING_END(str); const char *p1 = p; int rep7bit_p; - if (rb_block_given_p()) { + if (!replen) { rep = NULL; - replen = 0; rep7bit_p = FALSE; } else if (!NIL_P(repl)) { @@ -8484,7 +8489,10 @@ rb_enc_str_scrub(rb_encoding *enc, VALUE https://github.com/ruby/ruby/blob/trunk/ruby_2_2/string.c#L8489 const char *e = RSTRING_END(str); const char *p1 = p; long mbminlen = rb_enc_mbminlen(enc); - if (!NIL_P(repl)) { + if (!replen) { + rep = NULL; + } + else if (!NIL_P(repl)) { rep = RSTRING_PTR(repl); replen = RSTRING_LEN(repl); } @@ -8535,7 +8543,7 @@ rb_enc_str_scrub(rb_encoding *enc, VALUE https://github.com/ruby/ruby/blob/trunk/ruby_2_2/string.c#L8543 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)); Property changes on: ruby_2_2 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r57302-57304 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/