summaryrefslogtreecommitdiffstats
path: root/lib/redmine/codeset_util.rb
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2019-03-16 02:20:00 +0000
committerGo MAEDA <maeda@farend.jp>2019-03-16 02:20:00 +0000
commit1035b577a993761c854ae274b650c7c537d54c5b (patch)
tree2ab98c5c12219bd34e436646a559ea82460fff32 /lib/redmine/codeset_util.rb
parentccda34cac6267fa95bb17cf458078565ff5f8822 (diff)
downloadredmine-1035b577a993761c854ae274b650c7c537d54c5b.tar.gz
redmine-1035b577a993761c854ae274b650c7c537d54c5b.zip
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
Diffstat (limited to 'lib/redmine/codeset_util.rb')
-rw-r--r--lib/redmine/codeset_util.rb16
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/redmine/codeset_util.rb b/lib/redmine/codeset_util.rb
index e27da506f..23e1018a5 100644
--- a/lib/redmine/codeset_util.rb
+++ b/lib/redmine/codeset_util.rb
@@ -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'