diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-12-15 07:19:25 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-12-15 07:19:25 +0000 |
commit | 020fcc95fe948f65b03609d445a6cf1bc0c06dc5 (patch) | |
tree | 1fa20b692afb9923c84449d9757d8535f5165e5e | |
parent | b2a128fa7cabcce182e7360db70b3e50bb39242d (diff) | |
download | ruby-020fcc95fe948f65b03609d445a6cf1bc0c06dc5.tar.gz |
string.c: fix coderange for non-endianness string
* string.c (rb_enc_str_coderange): dummy wchar, non-endianness
encoding string cannot be ascii only.
[ruby-core:66835] [Bug #10598]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48845 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | string.c | 11 | ||||
-rw-r--r-- | test/ruby/test_m17n.rb | 8 |
3 files changed, 23 insertions, 2 deletions
@@ -1,3 +1,9 @@ +Mon Dec 15 16:19:23 2014 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * string.c (rb_enc_str_coderange): dummy wchar, non-endianness + encoding string cannot be ascii only. + [ruby-core:66835] [Bug #10598] + Sun Dec 14 20:11:42 2014 Nobuyoshi Nakada <nobu@ruby-lang.org> * parse.y (primary): restore current_arg so that circular @@ -487,8 +487,15 @@ rb_enc_str_coderange(VALUE str) int cr = ENC_CODERANGE(str); if (cr == ENC_CODERANGE_UNKNOWN) { - rb_encoding *enc = STR_ENC_GET(str); - cr = coderange_scan(RSTRING_PTR(str), RSTRING_LEN(str), enc); + int encidx = ENCODING_GET(str); + rb_encoding *enc = rb_enc_from_index(encidx); + if (rb_enc_mbminlen(enc) > 1 && rb_enc_dummy_p(enc)) { + cr = ENC_CODERANGE_BROKEN; + } + else { + cr = coderange_scan(RSTRING_PTR(str), RSTRING_LEN(str), + get_actual_encoding(encidx, str)); + } ENC_CODERANGE_SET(str, cr); } return cr; diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb index bbaf31f52a..99450723cf 100644 --- a/test/ruby/test_m17n.rb +++ b/test/ruby/test_m17n.rb @@ -260,6 +260,14 @@ class TestM17N < Test::Unit::TestCase end end + def test_utf_without_bom_asciionly + bug10598 = '[ruby-core:66835] [Bug #10598]' + encs = [Encoding::UTF_16, Encoding::UTF_32].find_all {|enc| + "abcd".force_encoding(enc).ascii_only? + } + assert_empty(encs, bug10598) + end + def test_object_utf16_32_inspect EnvUtil.suppress_warning do begin |