8000 merge revision(s) 51470: [Backport #11413] · github/ruby@26eb8e4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 26eb8e4

Browse files
committed
merge revision(s) 51470: [Backport ruby#11413]
* re.c (rb_memsearch): should match only char boundaries in wide character encodings. [ruby-core:70220] [Bug ruby#11413] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@51615 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 4bf7894 commit 26eb8e4

File tree

5 files changed

+48
-13
lines changed

5 files changed

+48
-13
lines changed

Chang 10000 eLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Mon Aug 17 17:57:12 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
2+
3+
* re.c (rb_memsearch): should match only char boundaries in wide
4+
character encodings. [ruby-core:70220] [Bug #11413]
5+
16
Mon Aug 17 17:54:33 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
27

38
* transcode.c (rb_econv_set_replacement): target encoding name can

re.c

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,32 @@ rb_memsearch_qs_utf8(const unsigned char *xs, long m, const unsigned char *ys, l
223223
return -1;
224224
}
225225

226+
static inline long
227+
rb_memsearch_wchar(const unsigned char *xs, long m, const unsigned char *ys, long n)
228+
{
229+
const unsigned char *x = xs, x0 = *xs, *y = ys;
230+
enum {char_size = 2};
231+
232+
for (n -= m; n > 0; n -= char_size, y += char_size) {
233+
if (x0 == *y && memcmp(x+1, y+1, m-1) == 0)
234+
return y - ys;
235+
}
236+
return -1;
237+
}
238+
239+
static inline long
240+
rb_memsearch_qchar(const unsigned char *xs, long m, const unsigned char *ys, long n)
241+
{
242+
const unsigned char *x = xs, x0 = *xs, *y = ys;
243+
enum {char_size = 4};
244+
245+
for (n -= m; n > 0; n -= char_size, y += char_size) {
246+
if (x0 == *y && memcmp(x+1, y+1, m-1) == 0)
247+
return y - ys;
248+
}
249+
return -1;
250+
}
251+
226252
long
227253
rb_memsearch(const void *x0, long m, const void *y0, long n, rb_encoding *enc)
228254
{
@@ -243,15 +269,21 @@ rb_memsearch(const void *x0, long m, const void *y0, long n, rb_encoding *enc)
243269
else
244270
return -1;
245271
}
246-
else if (m <= SIZEOF_VALUE) {
247-
return rb_memsearch_ss(x0, m, y0, n);
272+
else if (rb_enc_mbminlen(enc) == 1) {
273+
if (m <= SIZEOF_VALUE) {
274+
return rb_memsearch_ss(x0, m, y0, n);
275+
}
276+
else if (enc == rb_utf8_encoding()){
277+
return rb_memsearch_qs_utf8(x0, m, y0, n);
278+
}
248279
}
249-
else if (enc == rb_utf8_encoding()){
250-
return rb_memsearch_qs_utf8(x0, m, y0, n);
280+
else if (rb_enc_mbminlen(enc) == 2) {
281+
return rb_memsearch_wchar(x0, m, y0, n);
251282
}
252-
else {
253-
return rb_memsearch_qs(x0, m, y0, n);
283+
else if (rb_enc_mbminlen(enc) == 4) {
284+
return rb_memsearch_qchar(x0, m, y0, n);
254285
}
286+
return rb_memsearch_qs(x0, m, y0, n);
255287
}
256288

257289
#define REG_LITERAL FL_USER5

string.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6213,15 +6213,10 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str)
62136213
}
62146214

62156215
enc = STR_ENC_GET(str);
6216-
if (NIL_P(spat)) {
6217-
if (!NIL_P(rb_fs)) {
6218-
spat = rb_fs;
6219-
goto fs_set;
6220-
}
6216+
if (NIL_P(spat) && NIL_P(spat = rb_fs)) {
62216217
split_type = awk;
62226218
}
62236219
else {
6224-
fs_set:
62256220
if (RB_TYPE_P(spat, T_STRING)) {
62266221
rb_encoding *enc2 = STR_ENC_GET(spat);
62276222

test/ruby/test_m17n.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,9 @@ def test_split
12261226
each_encoding("abc,def", ",", "abc", "def") do |str, sep, *expected|
12271227
assert_equal(expected, str.split(sep, -1))
12281228
end
1229+
each_encoding("abc\0def", "\0", "abc", "def") do |str, sep, *expected|
1230+
assert_equal(expected, str.split(sep, -1))
1231+
end
12291232
end
12301233

12311234
def test_nonascii_method_name

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#define RUBY_VERSION "2.1.7"
22
#define RUBY_RELEASE_DATE "2015-08-17"
3-
#define RUBY_PATCHLEVEL 397
3+
#define RUBY_PATCHLEVEL 398
44

55
#define RUBY_RELEASE_YEAR 2015
66
#define RUBY_RELEASE_MONTH 8

0 commit comments

Comments
 (0)
0