summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--string.c23
-rw-r--r--test/ruby/test_string.rb4
-rw-r--r--version.h2
4 files changed, 31 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index cd45ab80af..ef02afe111 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Mon Mar 11 01:04:54 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 Mar 11 00:58:30 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* common.mk (realclean-local): miniprelude.c is made by srcs, so it
diff --git a/string.c b/string.c
index cbfac397fc..6eebd9e096 100644
--- a/string.c
+++ b/string.c
@@ -4122,10 +4122,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 7b4dc2951d..43be67893c 100644
--- a/test/ruby/test_string.rb
+++ b/test/ruby/test_string.rb
@@ -2180,6 +2180,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
diff --git a/version.h b/version.h
index 2974f7a24f..6ee2fe6f52 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.0.0"
#define RUBY_RELEASE_DATE "2013-03-11"
-#define RUBY_PATCHLEVEL 50
+#define RUBY_PATCHLEVEL 51
#define RUBY_RELEASE_YEAR 2013
#define RUBY_RELEASE_MONTH 3