summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-08-17 08:58:50 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-08-17 08:58:50 +0000
commit26eb8e4b4e39aee7c1e4e9c061c9c17daaafc78b (patch)
tree16905c844eb3e10fb7c7b8f0f18a13faf2ea8410
parent4bf78945ffe3fe696605a82ffcdcd69a4250667e (diff)
merge revision(s) 51470: [Backport #11413]
* re.c (rb_memsearch): should match only char boundaries in wide character encodings. [ruby-core:70220] [Bug #11413] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@51615 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--re.c44
-rw-r--r--string.c7
-rw-r--r--test/ruby/test_m17n.rb3
-rw-r--r--version.h2
5 files changed, 48 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index ad2ca2d9b7..b784bce87c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Mon Aug 17 17:57:12 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * re.c (rb_memsearch): should match only char boundaries in wide
+ character encodings. [ruby-core:70220] [Bug #11413]
+
Mon Aug 17 17:54:33 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* transcode.c (rb_econv_set_replacement): target encoding name can
diff --git a/re.c b/re.c
index d26b783466..ceb72b9377 100644
--- a/re.c
+++ b/re.c
@@ -223,6 +223,32 @@ rb_memsearch_qs_utf8(const unsigned char *xs, long m, const unsigned char *ys, l
return -1;
}
+static inline long
+rb_memsearch_wchar(const unsigned char *xs, long m, const unsigned char *ys, long n)
+{
+ const unsigned char *x = xs, x0 = *xs, *y = ys;
+ enum {char_size = 2};
+
+ for (n -= m; n > 0; n -= char_size, y += char_size) {
+ if (x0 == *y && memcmp(x+1, y+1, m-1) == 0)
+ return y - ys;
+ }
+ return -1;
+}
+
+static inline long
+rb_memsearch_qchar(const unsigned char *xs, long m, const unsigned char *ys, long n)
+{
+ const unsigned char *x = xs, x0 = *xs, *y = ys;
+ enum {char_size = 4};
+
+ for (n -= m; n > 0; n -= char_size, y += char_size) {
+ if (x0 == *y && memcmp(x+1, y+1, m-1) == 0)
+ return y - ys;
+ }
+ return -1;
+}
+
long
rb_memsearch(const void *x0, long m, const void *y0, long n, rb_encoding *enc)
{
@@ -243,15 +269,21 @@ rb_memsearch(const void *x0, long m, const void *y0, long n, rb_encoding *enc)
else
return -1;
}
- else if (m <= SIZEOF_VALUE) {
- return rb_memsearch_ss(x0, m, y0, n);
+ else if (rb_enc_mbminlen(enc) == 1) {
+ if (m <= SIZEOF_VALUE) {
+ return rb_memsearch_ss(x0, m, y0, n);
+ }
+ else if (enc == rb_utf8_encoding()){
+ return rb_memsearch_qs_utf8(x0, m, y0, n);
+ }
}
- else if (enc == rb_utf8_encoding()){
- return rb_memsearch_qs_utf8(x0, m, y0, n);
+ else if (rb_enc_mbminlen(enc) == 2) {
+ return rb_memsearch_wchar(x0, m, y0, n);
}
- else {
- return rb_memsearch_qs(x0, m, y0, n);
+ else if (rb_enc_mbminlen(enc) == 4) {
+ return rb_memsearch_qchar(x0, m, y0, n);
}
+ return rb_memsearch_qs(x0, m, y0, n);
}
#define REG_LITERAL FL_USER5
diff --git a/string.c b/string.c
index 0a4a789f00..859018e5c1 100644
--- a/string.c
+++ b/string.c
@@ -6213,15 +6213,10 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str)
}
enc = STR_ENC_GET(str);
- if (NIL_P(spat)) {
- if (!NIL_P(rb_fs)) {
- spat = rb_fs;
- goto fs_set;
- }
+ if (NIL_P(spat) && NIL_P(spat = rb_fs)) {
split_type = awk;
}
else {
- fs_set:
if (RB_TYPE_P(spat, T_STRING)) {
rb_encoding *enc2 = STR_ENC_GET(spat);
diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb
index 60818cd44e..8dc54e5f4b 100644
--- a/test/ruby/test_m17n.rb
+++ b/test/ruby/test_m17n.rb
@@ -1226,6 +1226,9 @@ class TestM17N < Test::Unit::TestCase
each_encoding("abc,def", ",", "abc", "def") do |str, sep, *expected|
assert_equal(expected, str.split(sep, -1))
end
+ each_encoding("abc\0def", "\0", "abc", "def") do |str, sep, *expected|
+ assert_equal(expected, str.split(sep, -1))
+ end
end
def test_nonascii_method_name
diff --git a/version.h b/version.h
index ab7224d081..9637c01abc 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.1.7"
#define RUBY_RELEASE_DATE "2015-08-17"
-#define RUBY_PATCHLEVEL 397
+#define RUBY_PATCHLEVEL 398
#define RUBY_RELEASE_YEAR 2015
#define RUBY_RELEASE_MONTH 8