summaryrefslogtreecommitdiff
path: root/test/ruby/test_m17n.rb
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-06-19 10:44:54 -0700
committerJeremy Evans <code@jeremyevans.net>2019-07-02 08:34:01 -0700
commit0f283054e7f568f09fbfc952d57ea6daf4abbd88 (patch)
tree18106e6c0c0f743ffcd5028e0ce0a564f3c89610 /test/ruby/test_m17n.rb
parent7582287eb27e6b649789ce31ffdcbbb9ffcaf726 (diff)
Check that String#scrub block does not modify receiver
Similar to the check used for String#gsub. Can fix possible segfault. Fixes [Bug #15941]
Diffstat (limited to 'test/ruby/test_m17n.rb')
-rw-r--r--test/ruby/test_m17n.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb
index 953f6417b0..44f3cc97a9 100644
--- a/test/ruby/test_m17n.rb
+++ b/test/ruby/test_m17n.rb
@@ -1604,6 +1604,19 @@ class TestM17N < Test::Unit::TestCase
assert_predicate(str.dup.taint.scrub, :tainted?)
end
+ def test_scrub_modification_inside_block
+ str = ("abc\u3042".b << "\xE3\x80".b).force_encoding('UTF-8')
+ assert_raise(RuntimeError) {str.scrub{|_| str << "1234567890"; "?" }}
+
+ str = "\x00\xD8\x42\x30".force_encoding(Encoding::UTF_16LE)
+ assert_raise(RuntimeError) do
+ str.scrub do |_|
+ str << "1\x002\x00".force_encoding('UTF-16LE')
+ "?\x00".force_encoding('UTF-16LE')
+ end
+ end
+ end
+
def test_scrub_replace_default
assert_equal("\uFFFD\uFFFD\uFFFD", u("\x80\x80\x80").scrub)
assert_equal("\uFFFDA", u("\xF4\x80\x80A").scrub)