Browse Source

do not replace all invalid utf8 (#24616)

git-svn-id: http://svn.redmine.org/redmine/trunk@16273 e93f8b46-1217-0410-a6f0-8f06a7374b81
tags/3.4.0
Toshi MARUYAMA 7 years ago
parent
commit
b2c0ea2c3e
2 changed files with 2 additions and 2 deletions
  1. 1
    1
      lib/redmine/codeset_util.rb
  2. 1
    1
      test/unit/lib/redmine/codeset_util_test.rb

+ 1
- 1
lib/redmine/codeset_util.rb View File

@@ -6,7 +6,7 @@ module Redmine
return str if str.nil?
str.force_encoding('UTF-8')
if ! str.valid_encoding?
str = str.encode("US-ASCII", :invalid => :replace,
str = str.encode("UTF-16LE", :invalid => :replace,
:undef => :replace, :replace => '?').encode("UTF-8")
end
str

+ 1
- 1
test/unit/lib/redmine/codeset_util_test.rb View File

@@ -91,7 +91,7 @@ class Redmine::CodesetUtilTest < ActiveSupport::TestCase
s2 = Redmine::CodesetUtil.replace_invalid_utf8(s1)
assert s2.valid_encoding?
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

test "#to_utf8 should replace invalid non utf8" do

Loading…
Cancel
Save