ruby-changes:37637
From: naruse <ko1@a...>
Date: Tue, 24 Feb 2015 16:41:01 +0900 (JST)
Subject: [ruby-changes:37637] naruse:r49718 (ruby_2_2): merge revision(s) 49706: [Backport #10893]
naruse 2015-02-24 16:40:44 +0900 (Tue, 24 Feb 2015) New Revision: 49718 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49718 Log: merge revision(s) 49706: [Backport #10893] * string.c (chompped_length): enable smart chomp for all non-dummy encoding strings, not only default_rs. [ruby-core:68258] [Bug #10893] Modified directories: branches/ruby_2_2/ Modified files: branches/ruby_2_2/ChangeLog branches/ruby_2_2/string.c branches/ruby_2_2/test/ruby/test_m17n_comb.rb branches/ruby_2_2/version.h Index: ruby_2_2/ChangeLog =================================================================== --- ruby_2_2/ChangeLog (revision 49717) +++ ruby_2_2/ChangeLog (revision 49718) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/ChangeLog#L1 +Tue Feb 24 16:37:26 2015 Nobuyoshi Nakada <nobu@r...> + + * string.c (chompped_length): enable smart chomp for all non-dummy + encoding strings, not only default_rs. + [ruby-core:68258] [Bug #10893] + Tue Feb 24 16:31:53 2015 Nobuyoshi Nakada <nobu@r...> * string.c (rb_str_split_m): raise ArgumentError at broken string Index: ruby_2_2/string.c =================================================================== --- ruby_2_2/string.c (revision 49717) +++ ruby_2_2/string.c (revision 49718) @@ -7109,9 +7109,9 @@ chompped_length(VALUE str, VALUE rs) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/string.c#L7109 if (len == 0) return 0; e = p + len; - enc = rb_enc_get(str); if (rs == rb_default_rs) { smart_chomp: + enc = rb_enc_get(str); if (rb_enc_mbminlen(enc) > 1) { pp = rb_enc_left_char_head(p, e-rb_enc_mbminlen(enc), e, enc); if (rb_enc_is_newline(pp, e, enc)) { @@ -7140,6 +7140,7 @@ chompped_length(VALUE str, VALUE rs) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/string.c#L7140 return e - p; } + enc = rb_enc_get(str); RSTRING_GETMEM(rs, rsptr, rslen); if (rslen == 0) { if (rb_enc_mbminlen(enc) > 1) { @@ -7167,10 +7168,7 @@ chompped_length(VALUE str, VALUE rs) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/string.c#L7168 } if (rslen > len) return len; - enc = rb_enc_check(str, rs); - if (is_broken_string(rs)) { - return len; - } + enc = rb_enc_get(rs); newline = rsptr[rslen-1]; if (rslen == rb_enc_mbminlen(enc)) { if (rslen == 1) { @@ -7183,6 +7181,10 @@ chompped_length(VALUE str, VALUE rs) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/string.c#L7181 } } + enc = rb_enc_check(str, rs); + if (is_broken_string(rs)) { + return len; + } pp = e - rslen; if (p[len-1] == newline && (rslen <= 1 || Index: ruby_2_2/version.h =================================================================== --- ruby_2_2/version.h (revision 49717) +++ ruby_2_2/version.h (revision 49718) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1 #define RUBY_VERSION "2.2.0" #define RUBY_RELEASE_DATE "2015-02-24" -#define RUBY_PATCHLEVEL 80 +#define RUBY_PATCHLEVEL 81 #define RUBY_RELEASE_YEAR 2015 #define RUBY_RELEASE_MONTH 2 Index: ruby_2_2/test/ruby/test_m17n_comb.rb =================================================================== --- ruby_2_2/test/ruby/test_m17n_comb.rb (revision 49717) +++ ruby_2_2/test/ruby/test_m17n_comb.rb (revision 49718) @@ -659,7 +659,9 @@ class TestM17NComb < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/ruby/test_m17n_comb.rb#L659 combination(STRINGS, STRINGS) {|s1, s2| if !s1.ascii_only? && !s2.ascii_only? && !Encoding.compatible?(s1,s2) if s1.bytesize > s2.bytesize - assert_raise(Encoding::CompatibilityError) { s1.chomp(s2) } + assert_raise(Encoding::CompatibilityError, "#{encdump(s1)}.chomp(#{encdump(s2)})") do + s1.chomp(s2) + end end next end @@ -672,6 +674,17 @@ class TestM17NComb < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/ruby/test_m17n_comb.rb#L674 } end + def test_str_smart_chomp + bug10893 = '[ruby-core:68258] [Bug #10893]' + encodings = Encoding.list.select {|enc| !enc.dummy?} + combination(encodings, encodings) do |e1, e2| + expected = "abc".encode(e1) + combination(["abc\n", "abc\r\n"], ["", "\n"]) do |str, rs| + assert_equal(expected, str.encode(e1).chomp(rs.encode(e2)), bug10893) + end + end + end + def test_str_chop STRINGS.each {|s| s = s.dup Property changes on: ruby_2_2 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r49706 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/