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

merge revision(s) 67167: [Backport #15635]

string.c: respect the actual encoding

	* string.c (rb_enc_str_coderange): respect the actual encoding of
	  if a BOM presents, and scan for the actual code range.
	  [ruby-core:91662] [Bug #15635]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_5@67192 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagachika 2019-03-07 15:31:42 +00:00
parent 7bd41bd2ca
commit bdd97e5f38
3 changed files with 11 additions and 3 deletions

View file

@ -626,12 +626,13 @@ rb_enc_str_coderange(VALUE str)
if (cr == ENC_CODERANGE_UNKNOWN) {
int encidx = ENCODING_GET(str);
rb_encoding *enc = rb_enc_from_index(encidx);
if (rb_enc_mbminlen(enc) > 1 && rb_enc_dummy_p(enc)) {
if (rb_enc_mbminlen(enc) > 1 && rb_enc_dummy_p(enc) &&
rb_enc_mbminlen(enc = get_actual_encoding(encidx, str)) == 1) {
cr = ENC_CODERANGE_BROKEN;
}
else {
cr = coderange_scan(RSTRING_PTR(str), RSTRING_LEN(str),
get_actual_encoding(encidx, str));
enc);
}
ENC_CODERANGE_SET(str, cr);
}

View file

@ -269,6 +269,13 @@ class TestM17N < Test::Unit::TestCase
assert_empty(encs, bug10598)
end
def test_utf_without_bom_valid
encs = [Encoding::UTF_16, Encoding::UTF_32].find_all {|enc|
!(+"abcd").encode!(enc).force_encoding(enc).valid_encoding?
}
assert_empty(encs)
end
def test_object_utf16_32_inspect
EnvUtil.suppress_warning do
begin

View file

@ -1,6 +1,6 @@
#define RUBY_VERSION "2.5.4"
#define RUBY_RELEASE_DATE "2019-03-08"
#define RUBY_PATCHLEVEL 142
#define RUBY_PATCHLEVEL 143
#define RUBY_RELEASE_YEAR 2019
#define RUBY_RELEASE_MONTH 3