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

ruby-changes:49922

From: nobu <ko1@a...>
Date: Thu, 25 Jan 2018 22:10:20 +0900 (JST)
Subject: [ruby-changes:49922] nobu:r62040 (trunk): string.c: clear substring code range

nobu	2018-01-25 22:10:14 +0900 (Thu, 25 Jan 2018)

  New Revision: 62040

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

  Log:
    string.c: clear substring code range
    
    * string.c (str_substr): substring of broken code range string may
      be valid or broken.  patch by tommy (Masahiro Tomita) at
      [ruby-dev:50430] [Bug #14388].

  Modified files:
    trunk/string.c
    trunk/test/ruby/test_string.rb
Index: string.c
===================================================================
--- string.c	(revision 62039)
+++ string.c	(revision 62040)
@@ -2560,6 +2560,7 @@ str_substr(VALUE str, long beg, long len https://github.com/ruby/ruby/blob/trunk/string.c#L2560
 	str2 = str_new_shared(rb_obj_class(str2), str2);
 	RSTRING(str2)->as.heap.ptr += ofs;
 	RSTRING(str2)->as.heap.len = len;
+	ENC_CODERANGE_CLEAR(str2);
     }
     else {
 	if (!len && !empty) return Qnil;
Index: test/ruby/test_string.rb
===================================================================
--- test/ruby/test_string.rb	(revision 62039)
+++ test/ruby/test_string.rb	(revision 62040)
@@ -3087,6 +3087,12 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L3087
     assert_equal("\u3042", "\u3042\u3043".chr)
     assert_equal('', ''.chr)
   end
+
+  def test_substr_code_range
+    data = "\xff" + "a"*200
+    assert_not_predicate(data, :valid_encoding?)
+    assert_predicate(data[100..-1], :valid_encoding?)
+  end
 end
 
 class TestString2 < TestString

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

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