@@ -29,7 +29,13 module AttachmentsHelper | |||||
29 | end |
|
29 | end | |
30 |
|
30 | |||
31 | def to_utf8(str) |
|
31 | def to_utf8(str) | |
32 | return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii |
|
32 | if str.respond_to?(:force_encoding) | |
|
33 | str.force_encoding('UTF-8') | |||
|
34 | return str if str.valid_encoding? | |||
|
35 | else | |||
|
36 | return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii | |||
|
37 | end | |||
|
38 | ||||
33 | begin |
|
39 | begin | |
34 | Iconv.conv('UTF-8//IGNORE', 'UTF-8', str + ' ')[0..-3] |
|
40 | Iconv.conv('UTF-8//IGNORE', 'UTF-8', str + ' ')[0..-3] | |
35 | rescue Iconv::InvalidEncoding |
|
41 | rescue Iconv::InvalidEncoding |
@@ -113,7 +113,13 module RepositoriesHelper | |||||
113 | end |
|
113 | end | |
114 |
|
114 | |||
115 | def to_utf8(str) |
|
115 | def to_utf8(str) | |
116 | return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii |
|
116 | if str.respond_to?(:force_encoding) | |
|
117 | str.force_encoding('UTF-8') | |||
|
118 | return str if str.valid_encoding? | |||
|
119 | else | |||
|
120 | return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii | |||
|
121 | end | |||
|
122 | ||||
117 | @encodings ||= Setting.repositories_encodings.split(',').collect(&:strip) |
|
123 | @encodings ||= Setting.repositories_encodings.split(',').collect(&:strip) | |
118 | @encodings.each do |encoding| |
|
124 | @encodings.each do |encoding| | |
119 | begin |
|
125 | begin |
@@ -227,7 +227,13 class Changeset < ActiveRecord::Base | |||||
227 | end |
|
227 | end | |
228 |
|
228 | |||
229 | def self.to_utf8(str) |
|
229 | def self.to_utf8(str) | |
230 | return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii |
|
230 | if str.respond_to?(:force_encoding) | |
|
231 | str.force_encoding('UTF-8') | |||
|
232 | return str if str.valid_encoding? | |||
|
233 | else | |||
|
234 | return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii | |||
|
235 | end | |||
|
236 | ||||
231 | encoding = Setting.commit_logs_encoding.to_s.strip |
|
237 | encoding = Setting.commit_logs_encoding.to_s.strip | |
232 | unless encoding.blank? || encoding == 'UTF-8' |
|
238 | unless encoding.blank? || encoding == 'UTF-8' | |
233 | begin |
|
239 | begin |
General Comments 0
You need to be logged in to leave comments.
Login now