diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-02-25 12:18:48 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-02-25 12:18:48 +0000 |
commit | 2d3808eeac6ea951797fa53cb857919aa0d7d4cf (patch) | |
tree | 4c7936efda84dff5680ed9a8b4013eb8f8c00235 | |
parent | 9156a04d9186114f570a1ee8fe5059ec23e0b192 (diff) |
* string.c (str_byte_substr): don't set coderange if it's not known.
[Bug #7954] [ruby-dev:47108]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39495 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | string.c | 23 | ||||
-rw-r--r-- | test/ruby/test_string.rb | 4 |
3 files changed, 30 insertions, 2 deletions
@@ -1,3 +1,8 @@ +Mon Feb 25 21:03:34 2013 NARUSE, Yui <naruse@ruby-lang.org> + + * string.c (str_byte_substr): don't set coderange if it's not known. + [Bug #7954] [ruby-dev:47108] + Mon Feb 25 16:47:02 2013 Nobuyoshi Nakada <nobu@ruby-lang.org> * common.mk (realclean-local): miniprelude.c is made by srcs, so it @@ -4124,10 +4124,29 @@ str_byte_substr(VALUE str, long beg, long len) } else { str2 = rb_str_new5(str, p, len); - rb_enc_cr_str_copy_for_substr(str2, str); - OBJ_INFECT(str2, str); } + str_enc_copy(str2, str); + + if (RSTRING_LEN(str2) == 0) { + if (!rb_enc_asciicompat(STR_ENC_GET(str))) + ENC_CODERANGE_SET(str2, ENC_CODERANGE_VALID); + else + ENC_CODERANGE_SET(str2, ENC_CODERANGE_7BIT); + } + else { + switch (ENC_CODERANGE(str)) { + case ENC_CODERANGE_7BIT: + ENC_CODERANGE_SET(str2, ENC_CODERANGE_7BIT); + break; + default: + ENC_CODERANGE_SET(str2, ENC_CODERANGE_UNKNOWN); + break; + } + } + + OBJ_INFECT(str2, str); + return str2; } diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index 4e55198a15..a0fb80f46e 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -2181,6 +2181,10 @@ class TestString < Test::Unit::TestCase assert_equal(u("\x81\x82"), "\u3042".byteslice(1..2)) assert_equal(u("\x82")+("\u3042"*9), ("\u3042"*10).byteslice(2, 28)) + + bug7954 = '[ruby-dev:47108]' + assert_equal(false, "\u3042".byteslice(0, 2).valid_encoding?) + assert_equal(false, ("\u3042"*10).byteslice(0, 20).valid_encoding?) end end |