Defect #24910 » converter_not_found.patch
| lib/redmine/codeset_util.rb (working copy) | ||
|---|---|---|
| 23 | 23 |
end |
| 24 | 24 |
enc = encoding.blank? ? "UTF-8" : encoding |
| 25 | 25 |
if enc.casecmp("UTF-8") != 0
|
| 26 |
str.force_encoding(enc) |
|
| 27 |
str = str.encode("UTF-8", :invalid => :replace,
|
|
| 26 |
begin |
|
| 27 |
str.force_encoding(enc) |
|
| 28 |
str = str.encode("UTF-8", :invalid => :replace,
|
|
| 28 | 29 |
:undef => :replace, :replace => '?') |
| 30 |
rescue Encoding::ConverterNotFoundError |
|
| 31 |
Rails.logger.warn ">>> ConverterNotFoundError (#{enc} to UTF-8)"
|
|
| 32 |
str = replace_invalid_utf8(str) |
|
| 33 |
end |
|
| 29 | 34 |
else |
| 30 | 35 |
str = replace_invalid_utf8(str) |
| 31 | 36 |
end |
| test/unit/lib/redmine/codeset_util_test.rb (working copy) | ||
|---|---|---|
| 101 | 101 |
assert_equal "UTF-8", s2.encoding.to_s |
| 102 | 102 |
assert_equal 'こんにち?', s2 |
| 103 | 103 |
end |
| 104 | ||
| 105 |
test "#to_utf8 should support not supported code page" do |
|
| 106 |
s1 = (+'không hợp lệ').force_encoding('Windows-1258')
|
|
| 107 |
s2 = Redmine::CodesetUtil.to_utf8(s1, 'Windows-1258') |
|
| 108 |
assert s2.valid_encoding? |
|
| 109 |
assert_equal 'UTF-8', s2.encoding.to_s |
|
| 110 |
assert_equal 'không hợp lệ', s2 |
|
| 111 |
end |
|
| 104 | 112 |
end |