1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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].

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62040 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2018-01-25 13:10:14 +00:00
parent 845b3cfbf4
commit 9237049efe
2 changed files with 7 additions and 0 deletions

View file

@ -2560,6 +2560,7 @@ str_substr(VALUE str, long beg, long len, int empty)
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;

View file

@ -3087,6 +3087,12 @@ CODE
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