From 42bf89945890b04ee11e5128d2db34cb3dd0b5a4 Mon Sep 17 00:00:00 2001 From: naruse Date: Sat, 20 Jul 2013 09:10:12 +0000 Subject: * string.c (rb_str_succ): add missing case NEIGHBOR_WRAPPED. r42078 caused buggy behavior like "\xFF".b -> "\x01\xFF".b git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42082 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ string.c | 9 ++++++++- test/ruby/test_m17n_comb.rb | 5 +++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 6049cd0c90..478658a1c6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sat Jul 20 17:46:03 2013 NARUSE, Yui + + * string.c (rb_str_succ): add missing case NEIGHBOR_WRAPPED. + r42078 caused buggy behavior like "\xFF".b -> "\x01\xFF".b + Sat Jul 20 15:22:38 2013 Koichi Sasada * array.c (rb_ary_resize): use simple memcpy because there are no new diff --git a/string.c b/string.c index f10dd3aa82..1d784e3ef7 100644 --- a/string.c +++ b/string.c @@ -3117,9 +3117,16 @@ rb_str_succ(VALUE orig) l = ONIGENC_MBCLEN_CHARFOUND_LEN(l); MEMCPY(tmp, s, char, l); neighbor = enc_succ_char(tmp, l, enc); - if (neighbor == NEIGHBOR_FOUND) { + switch (neighbor) { + case NEIGHBOR_FOUND: MEMCPY(s, tmp, char, l); return str; + break; + case NEIGHBOR_WRAPPED: + MEMCPY(s, tmp, char, l); + break; + case NEIGHBOR_NOT_CHAR: + break; } if (rb_enc_precise_mbclen(s, s+l, enc) != l) { /* wrapped to \0...\0. search next valid char. */ diff --git a/test/ruby/test_m17n_comb.rb b/test/ruby/test_m17n_comb.rb index 47a1f411c6..8069885793 100644 --- a/test/ruby/test_m17n_comb.rb +++ b/test/ruby/test_m17n_comb.rb @@ -1340,6 +1340,11 @@ class TestM17NComb < Test::Unit::TestCase end end + def test_str_succ2 + assert_equal("\x01\x00".force_encoding("US-ASCII"), "\x7f".force_encoding("US-ASCII").succ) + assert_equal("\x01\x00".b, "\xff".b.succ) + end + def test_str_hash combination(STRINGS, STRINGS) {|s1, s2| if s1.eql?(s2) -- cgit v1.2.3