ruby-changes:39519
From: usa <ko1@a...>
Date: Mon, 17 Aug 2015 16:44:53 +0900 (JST)
Subject: [ruby-changes:39519] usa:r51600 (ruby_2_1): merge revision(s) 51344: [Backport #11387]
usa 2015-08-17 16:44:41 +0900 (Mon, 17 Aug 2015) New Revision: 51600 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51600 Log: merge revision(s) 51344: [Backport #11387] * string.c (rb_str_reverse): reversed string is not a substring, and should not set coderange of the original string. [ruby-dev:49189] [Bug #11387] Modified directories: branches/ruby_2_1/ Modified files: branches/ruby_2_1/ChangeLog branches/ruby_2_1/string.c branches/ruby_2_1/test/ruby/test_m17n.rb branches/ruby_2_1/version.h Index: ruby_2_1/ChangeLog =================================================================== --- ruby_2_1/ChangeLog (revision 51599) +++ ruby_2_1/ChangeLog (revision 51600) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1 +Mon Aug 17 16:44:01 2015 Nobuyoshi Nakada <nobu@r...> + + * string.c (rb_str_reverse): reversed string is not a substring, + and should not set coderange of the original string. + [ruby-dev:49189] [Bug #11387] + Mon Aug 17 16:24:10 2015 Tanaka Akira <akr@f...> * lib/time.rb (strptime): Support %s.%N. Index: ruby_2_1/string.c =================================================================== --- ruby_2_1/string.c (revision 51599) +++ ruby_2_1/string.c (revision 51600) @@ -4544,13 +4544,14 @@ rb_str_reverse(VALUE str) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/string.c#L4544 rb_encoding *enc; VALUE rev; char *s, *e, *p; - int single = 1; + int cr; if (RSTRING_LEN(str) <= 1) return rb_str_dup(str); enc = STR_ENC_GET(str); rev = rb_str_new5(str, 0, RSTRING_LEN(str)); s = RSTRING_PTR(str); e = RSTRING_END(str); p = RSTRING_END(rev); + cr = ENC_CODERANGE(str); if (RSTRING_LEN(str) > 1) { if (single_byte_optimizable(str)) { @@ -4558,21 +4559,22 @@ rb_str_reverse(VALUE str) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/string.c#L4559 *--p = *s++; } } - else if (ENC_CODERANGE(str) == ENC_CODERANGE_VALID) { + else if (cr == ENC_CODERANGE_VALID) { while (s < e) { int clen = rb_enc_fast_mbclen(s, e, enc); - if (clen > 1 || (*s & 0x80)) single = 0; p -= clen; memcpy(p, s, clen); s += clen; } } else { + cr = rb_enc_asciicompat(enc) ? + ENC_CODERANGE_7BIT : ENC_CODERANGE_VALID; while (s < e) { int clen = rb_enc_mbclen(s, e, enc); - if (clen > 1 || (*s & 0x80)) single = 0; + if (clen > 1 || (*s & 0x80)) cr = ENC_CODERANGE_UNKNOWN; p -= clen; memcpy(p, s, clen); s += clen; @@ -4581,15 +4583,8 @@ rb_str_reverse(VALUE str) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/string.c#L4583 } STR_SET_LEN(rev, RSTRING_LEN(str)); OBJ_INFECT(rev, str); - if (ENC_CODERANGE(str) == ENC_CODERANGE_UNKNOWN) { - if (single) { - ENC_CODERANGE_SET(str, ENC_CODERANGE_7BIT); - } - else { - ENC_CODERANGE_SET(str, ENC_CODERANGE_VALID); - } - } - rb_enc_cr_str_copy_for_substr(rev, str); + str_enc_copy(rev, str); + ENC_CODERANGE_SET(rev, cr); return rev; } Index: ruby_2_1/version.h =================================================================== --- ruby_2_1/version.h (revision 51599) +++ ruby_2_1/version.h (revision 51600) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1 #define RUBY_VERSION "2.1.7" #define RUBY_RELEASE_DATE "2015-08-17" -#define RUBY_PATCHLEVEL 383 +#define RUBY_PATCHLEVEL 384 #define RUBY_RELEASE_YEAR 2015 #define RUBY_RELEASE_MONTH 8 Index: ruby_2_1/test/ruby/test_m17n.rb =================================================================== --- ruby_2_1/test/ruby/test_m17n.rb (revision 51599) +++ ruby_2_1/test/ruby/test_m17n.rb (revision 51600) @@ -1132,7 +1132,12 @@ class TestM17N < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_m17n.rb#L1132 end def test_reverse - assert_equal(u("\xf0jihgfedcba"), u("abcdefghij\xf0").reverse) + bug11387 = '[ruby-dev:49189] [Bug #11387]' + s1 = u("abcdefghij\xf0") + s2 = s1.reverse + assert_not_predicate(s1, :valid_encoding?, bug11387) + assert_equal(u("\xf0jihgfedcba"), s2) + assert_not_predicate(s2, :valid_encoding?, bug11387) end def test_reverse_bang Property changes on: ruby_2_1 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r51344 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/