summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-05 04:50:03 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-05 04:50:03 +0000
commitfc47ac274f3627836956904814ddebbce948480e (patch)
treed817f9ffc6f8ec589346ed4ef0d20cd5660d61ed
parentcad94dbe222bb3337bfabefb66d5fb05d28dc133 (diff)
merge revision(s) 46896-46898: [Backport #10078]
* string.c (rb_str_count): fix wrong single-byte optimization. 7bit ascii can be a trailing byte in Shift_JIS. [ruby-dev:48442] [Bug #10078] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@47401 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--string.c29
-rw-r--r--test/ruby/test_m17n.rb5
-rw-r--r--test/ruby/test_m17n_comb.rb13
-rw-r--r--version.h2
5 files changed, 42 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index 62d4bcc213..b6f3a4d594 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Fri Sep 5 13:44:53 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * string.c (rb_str_count): fix wrong single-byte optimization.
+ 7bit ascii can be a trailing byte in Shift_JIS.
+ [ruby-dev:48442] [Bug #10078]
+
Fri Sep 5 13:36:12 2014 NAKAMURA Usaku <usa@ruby-lang.org>
merge r46831 partially. these changes are from:
diff --git a/string.c b/string.c
index d6a5232411..81e78576ad 100644
--- a/string.c
+++ b/string.c
@@ -5794,21 +5794,25 @@ rb_str_count(int argc, VALUE *argv, VALUE str)
{
char table[TR_TABLE_SIZE];
rb_encoding *enc = 0;
- VALUE del = 0, nodel = 0;
+ VALUE del = 0, nodel = 0, tstr;
char *s, *send;
int i;
int ascompat;
rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
- for (i=0; i<argc; i++) {
- VALUE tstr = argv[i];
- unsigned char c;
- StringValue(tstr);
- enc = rb_enc_check(str, tstr);
- if (argc == 1 && RSTRING_LEN(tstr) == 1 && rb_enc_asciicompat(enc) &&
- (c = RSTRING_PTR(tstr)[0]) < 0x80 && !is_broken_string(str)) {
+ tstr = argv[0];
+ StringValue(tstr);
+ enc = rb_enc_check(str, tstr);
+ if (argc == 1) {
+ const char *ptstr;
+ if (RSTRING_LEN(tstr) == 1 && rb_enc_asciicompat(enc) &&
+ (ptstr = RSTRING_PTR(tstr),
+ ONIGENC_IS_ALLOWED_REVERSE_MATCH(enc, (const unsigned char *)ptstr, (const unsigned char *)ptstr+1)) &&
+ !is_broken_string(str)) {
int n = 0;
+ int clen;
+ unsigned char c = rb_enc_codepoint_len(ptstr, ptstr+1, &clen, enc);
s = RSTRING_PTR(str);
if (!s || RSTRING_LEN(str) == 0) return INT2FIX(0);
@@ -5818,7 +5822,14 @@ rb_str_count(int argc, VALUE *argv, VALUE str)
}
return INT2NUM(n);
}
- tr_setup_table(tstr, table, i==0, &del, &nodel, enc);
+ }
+
+ tr_setup_table(tstr, table, TRUE, &del, &nodel, enc);
+ for (i=1; i<argc; i++) {
+ tstr = argv[i];
+ StringValue(tstr);
+ enc = rb_enc_check(str, tstr);
+ tr_setup_table(tstr, table, FALSE, &del, &nodel, enc);
}
s = RSTRING_PTR(str);
diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb
index 5d7f101b59..380ce76687 100644
--- a/test/ruby/test_m17n.rb
+++ b/test/ruby/test_m17n.rb
@@ -1026,6 +1026,11 @@ class TestM17N < Test::Unit::TestCase
assert_raise(Encoding::CompatibilityError){s.count(a("\xa3\xb0"))}
end
+ def test_count_sjis_trailing_byte
+ bug10078 = '[ruby-dev:48442] [Bug #10078]'
+ assert_equal(0, s("\x98\x61").count("a"), bug10078)
+ end
+
def test_delete
assert_equal(1, e("\xa1\xa2").delete("z").length)
s = e("\xa3\xb0\xa3\xb1\xa3\xb2\xa3\xb3\xa3\xb4")
diff --git a/test/ruby/test_m17n_comb.rb b/test/ruby/test_m17n_comb.rb
index 2de7179996..bb16cce558 100644
--- a/test/ruby/test_m17n_comb.rb
+++ b/test/ruby/test_m17n_comb.rb
@@ -84,7 +84,7 @@ class TestM17NComb < Test::Unit::TestCase
r
end
- def enccall(recv, meth, *args, &block)
+ def encdumpcall(recv, meth, *args, &block)
desc = ''
if String === recv
desc << encdump(recv)
@@ -107,12 +107,18 @@ class TestM17NComb < Test::Unit::TestCase
if block
desc << ' {}'
end
+ desc
+ end
+
+ def assert_enccall(recv, meth, *args, &block)
+ desc = encdumpcall(recv, meth, *args, &block)
result = nil
assert_nothing_raised(desc) {
result = recv.send(meth, *args, &block)
}
result
end
+ alias enccall assert_enccall
def assert_str_enc_propagation(t, s1, s2)
if !s1.ascii_only?
@@ -705,12 +711,13 @@ class TestM17NComb < Test::Unit::TestCase
def test_str_count
combination(STRINGS, STRINGS) {|s1, s2|
+ desc = proc {encdumpcall(s1, :count, s2)}
if !s1.valid_encoding? || !s2.valid_encoding?
- assert_raise(ArgumentError, Encoding::CompatibilityError) { s1.count(s2) }
+ assert_raise(ArgumentError, Encoding::CompatibilityError, desc) { s1.count(s2) }
next
end
if !s1.ascii_only? && !s2.ascii_only? && s1.encoding != s2.encoding
- assert_raise(Encoding::CompatibilityError) { s1.count(s2) }
+ assert_raise(Encoding::CompatibilityError, desc) { s1.count(s2) }
next
end
n = enccall(s1, :count, s2)
diff --git a/version.h b/version.h
index fff4ce6241..d5ad31efbe 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.0.0"
#define RUBY_RELEASE_DATE "2014-09-05"
-#define RUBY_PATCHLEVEL 550
+#define RUBY_PATCHLEVEL 551
#define RUBY_RELEASE_YEAR 2014
#define RUBY_RELEASE_MONTH 9