diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-07-20 09:10:12 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-07-20 09:10:12 +0000 |
commit | 42bf89945890b04ee11e5128d2db34cb3dd0b5a4 (patch) | |
tree | aa40f18385130e5f4fc91a7c8f68e0924255e8d8 | |
parent | 3a20287053640a97896f701f264f8a0fccec7c6a (diff) | |
download | ruby-42bf89945890b04ee11e5128d2db34cb3dd0b5a4.tar.gz |
* 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
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | string.c | 9 | ||||
-rw-r--r-- | test/ruby/test_m17n_comb.rb | 5 |
3 files changed, 18 insertions, 1 deletions
@@ -1,3 +1,8 @@ +Sat Jul 20 17:46:03 2013 NARUSE, Yui <naruse@ruby-lang.org> + + * 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 <ko1@atdot.net> * array.c (rb_ary_resize): use simple memcpy because there are no new @@ -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) |