diff --git a/string.c b/string.c index 0a5f802452..c065a8e2b6 100644 --- a/string.c +++ b/string.c @@ -2451,6 +2451,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; diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index 6a055f1330..a375ff5de8 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -2569,6 +2569,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 diff --git a/version.h b/version.h index 6c44937809..7c9e0c5b4e 100644 --- a/version.h +++ b/version.h @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.4.4" #define RUBY_RELEASE_DATE "2018-03-21" -#define RUBY_PATCHLEVEL 278 +#define RUBY_PATCHLEVEL 279 #define RUBY_RELEASE_YEAR 2018 #define RUBY_RELEASE_MONTH 3