From 95a6be1a177976e75e06c1a8f55b438898bee3a2 Mon Sep 17 00:00:00 2001 From: naruse Date: Fri, 22 Nov 2013 08:50:14 +0000 Subject: * transcode.c (str_transcode0): don't scrub invalid chars if str.encode doesn't have explicit invalid: :replace. workaround fix for see #8995 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43802 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_transcode.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test/ruby/test_transcode.rb') diff --git a/test/ruby/test_transcode.rb b/test/ruby/test_transcode.rb index db91010c94..25c9d24663 100644 --- a/test/ruby/test_transcode.rb +++ b/test/ruby/test_transcode.rb @@ -2071,4 +2071,13 @@ class TestTranscode < Test::Unit::TestCase assert_equal(4, 'aaa'.encode(enc).length, "should count in #{enc} with BOM") end end + + def test_encode_with_invalid_chars + bug8995 = '[ruby-dev:47747]' + EnvUtil.with_default_internal(Encoding::UTF_8) do + str = "\xff".force_encoding('utf-8') + assert_equal str, str.encode, bug8995 + assert_equal "\ufffd", str.encode(invalid: :replace), bug8995 + end + end end -- cgit v1.2.3