From 460528289ab3b22f373c00a8494f65e5c3dcfdde Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 4 Jan 2012 05:24:39 +0000 Subject: [PATCH] * 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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34208 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ string.c | 1 + test/ruby/test_m17n.rb | 9 +++++++++ 3 files changed, 16 insertions(+) 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 + + * 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 * 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"}