diff --git a/ChangeLog b/ChangeLog index 8fa08a2cd7..0711bfa1fc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri Nov 1 20:53:56 2013 Nobuyoshi Nakada + + * string.c (rb_str_scrub): fix typo, should yield invalid byte + sequence to be scrubbed. reported by znz at IRC. + Fri Nov 1 17:25:30 2013 Nobuyoshi Nakada * gc.c (is_live_object): finalizer may not run because of lazy-sweep. diff --git a/string.c b/string.c index 191f846d36..dbfce96788 100644 --- a/string.c +++ b/string.c @@ -8069,7 +8069,7 @@ rb_str_scrub(VALUE str, VALUE repl) if (!rep7bit_p) cr = ENC_CODERANGE_VALID; } else { - repl = rb_yield(rb_enc_str_new(p1, clen, enc)); + repl = rb_yield(rb_enc_str_new(p, clen, enc)); repl = str_compat_and_valid(repl, enc); rb_str_buf_cat(buf, RSTRING_PTR(repl), RSTRING_LEN(repl)); if (ENC_CODERANGE(repl) == ENC_CODERANGE_VALID) diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb index 183df6e13e..f23ba9cb9b 100644 --- a/test/ruby/test_m17n.rb +++ b/test/ruby/test_m17n.rb @@ -1524,6 +1524,9 @@ class TestM17N < Test::Unit::TestCase assert_raise(ArgumentError){ u("\xE3\x81\x82\xE3\x81\x82\xE3\x81").scrub{u("\x81")} } assert_equal(e("\xA4\xA2\xA2\xAE"), e("\xA4\xA2\xA4").scrub{e("\xA2\xAE")}) + assert_equal("\x81", u("a\x81").scrub {|c| break c}) + assert_raise(ArgumentError) {u("a\x81").scrub {|c| c}} + assert_equal("\uFFFD\u3042".encode("UTF-16BE"), "\xD8\x00\x30\x42".force_encoding(Encoding::UTF_16BE). scrub)