diff options
author | Louise Crow <louise.crow@gmail.com> | 2015-05-28 10:57:19 +0100 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2015-05-28 10:57:19 +0100 |
commit | e936b687a7df62dc69d1cc0493492346bd8e300a (patch) | |
tree | 61206adc9f66b7bfc691174c9f93c92ccea1ffe9 /lib/normalize_string.rb | |
parent | c6e8e298fd0861cd822f23f370a01ccbc21cb9d3 (diff) | |
parent | 495f82365ccd374d5b33339abce356f3a3662295 (diff) |
Merge branch 'force-filenames-to-utf8' into rails-3-develop
Diffstat (limited to 'lib/normalize_string.rb')
-rw-r--r-- | lib/normalize_string.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/normalize_string.rb b/lib/normalize_string.rb index 409262b8e..d850d7e05 100644 --- a/lib/normalize_string.rb +++ b/lib/normalize_string.rb @@ -73,6 +73,20 @@ def convert_string_to_utf8_or_binary(s, suggested_character_encoding=nil) result end +def convert_string_to_utf8(s, suggested_character_encoding=nil) + begin + result = normalize_string_to_utf8 s, suggested_character_encoding + rescue EncodingNormalizationError + result = s + if String.method_defined?(:encode) + result = s.force_encoding("utf-8").encode("utf-8", :invalid => :replace, + :undef => :replace, + :replace => "") + end + end + result +end + def log_text_details(message, text) if String.method_defined?(:encode) STDERR.puts "#{message}, we have text: #{text}, of class #{text.class} and encoding #{text.encoding}" |