diff --git a/ChangeLog b/ChangeLog index 6f0d63ef39..d5a8a6cb83 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,7 @@ -Wed Dec 26 07:31:19 2012 Nobuyoshi Nakada +Wed Dec 26 07:31:24 2012 Nobuyoshi Nakada + + * string.c (rb_enc_cr_str_copy_for_substr): empty string is always + valid or 7bit. * string.c (rb_str_enumerate_lines, rb_str_chop): reduce duplicated code. diff --git a/string.c b/string.c index 26af8b613f..a3f937d19e 100644 --- a/string.c +++ b/string.c @@ -293,6 +293,13 @@ rb_enc_cr_str_copy_for_substr(VALUE dest, VALUE src) * from src to new string "dest" which is made from the part of src. */ str_enc_copy(dest, src); + if (RSTRING_LEN(dest) == 0) { + if (!rb_enc_asciicompat(STR_ENC_GET(src))) + ENC_CODERANGE_SET(dest, ENC_CODERANGE_VALID); + else + ENC_CODERANGE_SET(dest, ENC_CODERANGE_7BIT); + return; + } switch (ENC_CODERANGE(src)) { case ENC_CODERANGE_7BIT: ENC_CODERANGE_SET(dest, ENC_CODERANGE_7BIT); @@ -305,12 +312,6 @@ rb_enc_cr_str_copy_for_substr(VALUE dest, VALUE src) ENC_CODERANGE_SET(dest, ENC_CODERANGE_7BIT); break; default: - if (RSTRING_LEN(dest) == 0) { - if (!rb_enc_asciicompat(STR_ENC_GET(src))) - ENC_CODERANGE_SET(dest, ENC_CODERANGE_VALID); - else - ENC_CODERANGE_SET(dest, ENC_CODERANGE_7BIT); - } break; } }