mirror of
https://github.com/meineerde/redmine.git
synced 2025-12-28 19:29:38 +00:00
Fix that methods in Redmine::CodesetUtil destroy the original string (#26561).
git-svn-id: http://svn.redmine.org/redmine/trunk@17974 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
ccda34cac6
commit
1035b577a9
@ -1,10 +1,11 @@
|
||||
# frozen_string_literal: false
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Redmine
|
||||
module CodesetUtil
|
||||
|
||||
def self.replace_invalid_utf8(str)
|
||||
return str if str.nil?
|
||||
return nil if str.nil?
|
||||
str = str.dup
|
||||
str.force_encoding('UTF-8')
|
||||
if ! str.valid_encoding?
|
||||
str = str.encode("UTF-16LE", :invalid => :replace,
|
||||
@ -14,7 +15,8 @@ module Redmine
|
||||
end
|
||||
|
||||
def self.to_utf8(str, encoding)
|
||||
return str if str.nil?
|
||||
return if str.nil?
|
||||
str = str.dup
|
||||
str.force_encoding("ASCII-8BIT")
|
||||
if str.empty?
|
||||
str.force_encoding("UTF-8")
|
||||
@ -32,12 +34,14 @@ module Redmine
|
||||
end
|
||||
|
||||
def self.to_utf8_by_setting(str)
|
||||
return str if str.nil?
|
||||
return if str.nil?
|
||||
str = str.dup
|
||||
self.to_utf8_by_setting_internal(str).force_encoding('UTF-8')
|
||||
end
|
||||
|
||||
def self.to_utf8_by_setting_internal(str)
|
||||
return str if str.nil?
|
||||
return if str.nil?
|
||||
str = str.dup
|
||||
str.force_encoding('ASCII-8BIT')
|
||||
return str if str.empty?
|
||||
return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
|
||||
@ -56,6 +60,8 @@ module Redmine
|
||||
end
|
||||
|
||||
def self.from_utf8(str, encoding)
|
||||
return if str.nil?
|
||||
str = str.dup
|
||||
str ||= ''
|
||||
str.force_encoding('UTF-8')
|
||||
if encoding.upcase != 'UTF-8'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user