Commit f6e98d6c authored by marutosijp's avatar marutosijp
Browse files

do not replace all invalid utf8 (#24616)

git-svn-id: https://svn.redmine.org/redmine/trunk@16273 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 90113134
...@@ -6,7 +6,7 @@ module Redmine ...@@ -6,7 +6,7 @@ module Redmine
return str if str.nil? return str if str.nil?
str.force_encoding('UTF-8') str.force_encoding('UTF-8')
if ! str.valid_encoding? if ! str.valid_encoding?
str = str.encode("US-ASCII", :invalid => :replace, str = str.encode("UTF-16LE", :invalid => :replace,
:undef => :replace, :replace => '?').encode("UTF-8") :undef => :replace, :replace => '?').encode("UTF-8")
end end
str str
......
...@@ -91,7 +91,7 @@ class Redmine::CodesetUtilTest < ActiveSupport::TestCase ...@@ -91,7 +91,7 @@ class Redmine::CodesetUtilTest < ActiveSupport::TestCase
s2 = Redmine::CodesetUtil.replace_invalid_utf8(s1) s2 = Redmine::CodesetUtil.replace_invalid_utf8(s1)
assert s2.valid_encoding? assert s2.valid_encoding?
assert_equal "UTF-8", s2.encoding.to_s assert_equal "UTF-8", s2.encoding.to_s
assert_equal "??????", s2 assert_equal "\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1??".force_encoding("UTF-8"), s2
end end
test "#to_utf8 should replace invalid non utf8" do test "#to_utf8 should replace invalid non utf8" do
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment