@@ -0,0 +1,31 | |||||
|
1 | require 'iconv' | |||
|
2 | ||||
|
3 | module Redmine | |||
|
4 | module CodesetUtil | |||
|
5 | ||||
|
6 | def self.replace_invalid_utf8(str) | |||
|
7 | return str if str.nil? | |||
|
8 | if str.respond_to?(:force_encoding) | |||
|
9 | str.force_encoding('UTF-8') | |||
|
10 | if ! str.valid_encoding? | |||
|
11 | str = str.encode("US-ASCII", :invalid => :replace, | |||
|
12 | :undef => :replace, :replace => '?').encode("UTF-8") | |||
|
13 | end | |||
|
14 | else | |||
|
15 | ic = Iconv.new('UTF-8', 'UTF-8') | |||
|
16 | txtar = "" | |||
|
17 | begin | |||
|
18 | txtar += ic.iconv(str) | |||
|
19 | rescue Iconv::IllegalSequence | |||
|
20 | txtar += $!.success | |||
|
21 | str = '?' + $!.failed[1,$!.failed.length] | |||
|
22 | retry | |||
|
23 | rescue | |||
|
24 | txtar += $!.success | |||
|
25 | end | |||
|
26 | str = txtar | |||
|
27 | end | |||
|
28 | str | |||
|
29 | end | |||
|
30 | end | |||
|
31 | end |
@@ -16,6 +16,7 | |||||
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require 'iconv' |
|
18 | require 'iconv' | |
|
19 | require 'redmine/codeset_util' | |||
19 |
|
20 | |||
20 | module RepositoriesHelper |
|
21 | module RepositoriesHelper | |
21 | def format_revision(revision) |
|
22 | def format_revision(revision) | |
@@ -143,35 +144,10 module RepositoriesHelper | |||||
143 | # do nothing here and try the next encoding |
|
144 | # do nothing here and try the next encoding | |
144 | end |
|
145 | end | |
145 | end |
|
146 | end | |
146 | str = replace_invalid_utf8(str) |
|
147 | str = Redmine::CodesetUtil.replace_invalid_utf8(str) | |
147 | end |
|
148 | end | |
148 | private :to_utf8_internal |
|
149 | private :to_utf8_internal | |
149 |
|
150 | |||
150 | def replace_invalid_utf8(str) |
|
|||
151 | return str if str.nil? |
|
|||
152 | if str.respond_to?(:force_encoding) |
|
|||
153 | str.force_encoding('UTF-8') |
|
|||
154 | if ! str.valid_encoding? |
|
|||
155 | str = str.encode("US-ASCII", :invalid => :replace, |
|
|||
156 | :undef => :replace, :replace => '?').encode("UTF-8") |
|
|||
157 | end |
|
|||
158 | else |
|
|||
159 | ic = Iconv.new('UTF-8', 'UTF-8') |
|
|||
160 | txtar = "" |
|
|||
161 | begin |
|
|||
162 | txtar += ic.iconv(str) |
|
|||
163 | rescue Iconv::IllegalSequence |
|
|||
164 | txtar += $!.success |
|
|||
165 | str = '?' + $!.failed[1,$!.failed.length] |
|
|||
166 | retry |
|
|||
167 | rescue |
|
|||
168 | txtar += $!.success |
|
|||
169 | end |
|
|||
170 | str = txtar |
|
|||
171 | end |
|
|||
172 | str |
|
|||
173 | end |
|
|||
174 |
|
||||
175 | def repository_field_tags(form, repository) |
|
151 | def repository_field_tags(form, repository) | |
176 | method = repository.class.name.demodulize.underscore + "_field_tags" |
|
152 | method = repository.class.name.demodulize.underscore + "_field_tags" | |
177 | if repository.is_a?(Repository) && |
|
153 | if repository.is_a?(Repository) && |
@@ -1,8 +1,8 | |||||
1 | <% @entries.each do |entry| %> |
|
1 | <% @entries.each do |entry| %> | |
2 | <% tr_id = Digest::MD5.hexdigest(entry.path) |
|
2 | <% tr_id = Digest::MD5.hexdigest(entry.path) | |
3 | depth = params[:depth].to_i %> |
|
3 | depth = params[:depth].to_i %> | |
4 | <% ent_path = replace_invalid_utf8(entry.path) %> |
|
4 | <% ent_path = Redmine::CodesetUtil.replace_invalid_utf8(entry.path) %> | |
5 | <% ent_name = replace_invalid_utf8(entry.name) %> |
|
5 | <% ent_name = Redmine::CodesetUtil.replace_invalid_utf8(entry.name) %> | |
6 | <tr id="<%= tr_id %>" class="<%= h params[:parent_id] %> entry <%= entry.kind %>"> |
|
6 | <tr id="<%= tr_id %>" class="<%= h params[:parent_id] %> entry <%= entry.kind %>"> | |
7 | <td style="padding-left: <%=18 * depth%>px;" class="filename"> |
|
7 | <td style="padding-left: <%=18 * depth%>px;" class="filename"> | |
8 | <% if entry.is_dir? %> |
|
8 | <% if entry.is_dir? %> | |
@@ -21,7 +21,7 | |||||
21 | <% changeset = @project.repository.find_changeset_by_name(entry.lastrev.identifier) if entry.lastrev && entry.lastrev.identifier %> |
|
21 | <% changeset = @project.repository.find_changeset_by_name(entry.lastrev.identifier) if entry.lastrev && entry.lastrev.identifier %> | |
22 | <td class="revision"><%= link_to_revision(changeset, @project) if changeset %></td> |
|
22 | <td class="revision"><%= link_to_revision(changeset, @project) if changeset %></td> | |
23 | <td class="age"><%= distance_of_time_in_words(entry.lastrev.time, Time.now) if entry.lastrev && entry.lastrev.time %></td> |
|
23 | <td class="age"><%= distance_of_time_in_words(entry.lastrev.time, Time.now) if entry.lastrev && entry.lastrev.time %></td> | |
24 | <td class="author"><%= changeset.nil? ? h(replace_invalid_utf8(entry.lastrev.author.to_s.split('<').first)) : changeset.author if entry.lastrev %></td> |
|
24 | <td class="author"><%= changeset.nil? ? h(Redmine::CodesetUtil.replace_invalid_utf8(entry.lastrev.author.to_s.split('<').first)) : changeset.author if entry.lastrev %></td> | |
25 | <td class="comments"><%=h truncate(changeset.comments, :length => 50) unless changeset.nil? %></td> |
|
25 | <td class="comments"><%=h truncate(changeset.comments, :length => 50) unless changeset.nil? %></td> | |
26 | </tr> |
|
26 | </tr> | |
27 | <% end %> |
|
27 | <% end %> |
General Comments 0
You need to be logged in to leave comments.
Login now