[#444] Fix Changeset#to_utf8 coding standards
This commit is contained in:
parent
0f7ae9b658
commit
f518251d5f
|
@ -245,21 +245,21 @@ class Changeset < ActiveRecord::Base
|
||||||
str.force_encoding("UTF-8") if str.respond_to?(:force_encoding)
|
str.force_encoding("UTF-8") if str.respond_to?(:force_encoding)
|
||||||
return str
|
return str
|
||||||
end
|
end
|
||||||
enc = encoding.blank? ? "UTF-8" : encoding
|
normalized_encoding = encoding.blank? ? "UTF-8" : encoding
|
||||||
if str.respond_to?(:force_encoding)
|
if str.respond_to?(:force_encoding)
|
||||||
if enc.upcase != "UTF-8"
|
if normalized_encoding.upcase != "UTF-8"
|
||||||
str.force_encoding(enc)
|
str.force_encoding(normalized_encoding)
|
||||||
str = str.encode("UTF-8", :invalid => :replace,
|
str = str.encode("UTF-8", :invalid => :replace,
|
||||||
:undef => :replace, :replace => '?')
|
:undef => :replace, :replace => '?')
|
||||||
else
|
else
|
||||||
str.force_encoding("UTF-8")
|
str.force_encoding("UTF-8")
|
||||||
if ! str.valid_encoding?
|
unless str.valid_encoding?
|
||||||
str = str.encode("US-ASCII", :invalid => :replace,
|
str = str.encode("US-ASCII", :invalid => :replace,
|
||||||
:undef => :replace, :replace => '?').encode("UTF-8")
|
:undef => :replace, :replace => '?').encode("UTF-8")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
ic = Iconv.new('UTF-8', enc)
|
ic = Iconv.new('UTF-8', normalized_encoding)
|
||||||
txtar = ""
|
txtar = ""
|
||||||
begin
|
begin
|
||||||
txtar += ic.iconv(str)
|
txtar += ic.iconv(str)
|
||||||
|
|
Loading…
Reference in New Issue