summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--string.c1
-rw-r--r--test/ruby/test_m17n.rb9
3 files changed, 16 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 81182f2cda..84e3283712 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Wed Jan 4 14:24:33 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * string.c (str_nth_len): count ascii-only run at the end. this
+ bug appears only when single-byte-optimization is disabled due
+ to unknown coderange. [ruby-core:41896] [Bug #5836]
+
Wed Jan 4 11:32:07 2012 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (check_valid_dir): special case for a root directory.
diff --git a/string.c b/string.c
index 61703a7057..606fef7a42 100644
--- a/string.c
+++ b/string.c
@@ -1483,6 +1483,7 @@ str_nth_len(const char *p, const char *e, long *nthp, rb_encoding *enc)
if (ISASCII(*p)) {
p2 = search_nonascii(p, e2);
if (!p2) {
+ nth -= e2 - p;
*nthp = nth;
return (char *)e2;
}
diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb
index f4d3dcbdad..cc42514da2 100644
--- a/test/ruby/test_m17n.rb
+++ b/test/ruby/test_m17n.rb
@@ -930,6 +930,15 @@ class TestM17N < Test::Unit::TestCase
assert_equal("\u{439}", "a\u{439}bcdefghijklmnop"[1, 1][0, 1], bug2379)
end
+ def test_str_aref_force_encoding
+ bug5836 = '[ruby-core:41896]'
+ Encoding.list.each do |enc|
+ next unless enc.ascii_compatible?
+ s = "abc".force_encoding(enc)
+ assert_equal("", s[3, 1], bug5836)
+ end
+ end
+
def test_aset
s = e("\xa3\xb0\xa3\xb1\xa3\xb2\xa3\xb3\xa3\xb4")
assert_raise(Encoding::CompatibilityError){s["\xb0\xa3"] = "foo"}