From edaf78dfb69db9794e4ddf4f0a658c374e857924 Mon Sep 17 00:00:00 2001 From: drbrain Date: Sun, 6 Feb 2011 03:54:50 +0000 Subject: Ensure result encoding is the same as input encoding for String#gsub. [Bug #4340]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30806 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_string.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test/ruby/test_string.rb') diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index 972f326ab2..9440f93ed4 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -674,6 +674,21 @@ class TestString < Test::Unit::TestCase assert_raise(ArgumentError) { "foo".gsub } end + def test_gsub_encoding + a = S("hello world") + a.force_encoding Encoding::UTF_8 + + b = S("hi") + b.force_encoding Encoding::US_ASCII + + assert_equal Encoding::UTF_8, a.gsub(/hello/, b).encoding + + c = S("everybody") + c.force_encoding Encoding::US_ASCII + + assert_equal Encoding::UTF_8, a.gsub(/world/, c).encoding + end + def test_gsub! a = S("hello") b = a.dup -- cgit v1.2.3