summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--string.c6
-rw-r--r--test/ruby/test_m17n.rb5
2 files changed, 10 insertions, 1 deletions
diff --git a/string.c b/string.c
index 494dc1d90e..c01f2e595b 100644
--- a/string.c
+++ b/string.c
@@ -9345,7 +9345,11 @@ rb_enc_str_scrub(rb_encoding *enc, VALUE str, VALUE repl)
const char *e = RSTRING_END(str);
const char *p1 = p;
long mbminlen = rb_enc_mbminlen(enc);
- if (!NIL_P(repl)) {
+ if (rb_block_given_p()) {
+ rep = NULL;
+ replen = 0;
+ }
+ else if (!NIL_P(repl)) {
rep = RSTRING_PTR(repl);
replen = RSTRING_LEN(repl);
}
diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb
index 8b7e7e6b4a..c610f71216 100644
--- a/test/ruby/test_m17n.rb
+++ b/test/ruby/test_m17n.rb
@@ -1640,6 +1640,11 @@ class TestM17N < Test::Unit::TestCase
assert_equal("\uFFFD".encode("UTF-32LE"),
"\xff".force_encoding(Encoding::UTF_32LE).
scrub)
+ c = nil
+ assert_equal("?".encode(Encoding::UTF_16LE),
+ "\x00\xD8".force_encoding(Encoding::UTF_16LE).
+ scrub {|e| c = e; "?".encode(Encoding::UTF_16LE)})
+ assert_equal("\x00\xD8".force_encoding(Encoding::UTF_16LE), c)
end
def test_scrub_dummy_encoding