From 800704a212a08a4d6c8c22dceb1bb8df914b95dd Mon Sep 17 00:00:00 2001 From: Sho DOUHASHI Date: Thu, 10 Jan 2013 00:24:03 +0900 Subject: [PATCH 1/5] fix encoding error --- app/views/importer/result.html.erb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/views/importer/result.html.erb b/app/views/importer/result.html.erb index 1c17ef7..84a3b29 100644 --- a/app/views/importer/result.html.erb +++ b/app/views/importer/result.html.erb @@ -23,7 +23,11 @@ <% @failed_issues.each do |id, issue| -%> "> <%= id %> - <% issue.each do |column| %><%= content_tag 'td', column[1] %><% end %> + <% issue.each do |column| %> + <%- data = column[1] %> + <%- data = data.unpack('U*').pack('U*') if data.is_a?(String) -%> + <%= content_tag 'td', data %> + <% end %> <% end %> From 58870f69637e9bc39b40db887865306e5db52d3d Mon Sep 17 00:00:00 2001 From: Sho DOUHASHI Date: Thu, 10 Jan 2013 01:09:46 +0900 Subject: [PATCH 2/5] detect encoding --- app/models/import_in_progress.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/app/models/import_in_progress.rb b/app/models/import_in_progress.rb index 33f35ed..4d27c17 100644 --- a/app/models/import_in_progress.rb +++ b/app/models/import_in_progress.rb @@ -1,5 +1,30 @@ +require 'nkf' class ImportInProgress < ActiveRecord::Base unloadable belongs_to :user belongs_to :project + + before_save :encode_csv_data + + private + def encode_csv_data + return if self.csv_data.blank? + + self.csv_data = self.csv_data + # 入力文字コード + encode = case self.encoding + when "U" + "-W" + when "EUC" + "-E" + when "S" + "-S" + when "N" + "" + else + "" + end + + self.csv_data = NKF.nkf("#{encode} -w", self.csv_data) + end end From f26eb52315af46c7c58cac61af02308ee3d1d096 Mon Sep 17 00:00:00 2001 From: Sho DOUHASHI Date: Thu, 10 Jan 2013 01:31:38 +0900 Subject: [PATCH 3/5] fix encode error --- app/views/importer/match.html.erb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/importer/match.html.erb b/app/views/importer/match.html.erb index 3c4e9e5..4383254 100644 --- a/app/views/importer/match.html.erb +++ b/app/views/importer/match.html.erb @@ -30,8 +30,8 @@ <% matched = '' @attrs.each do |k,v| if v.to_s.casecmp(column.to_s.sub(" ") {|sp| "_" }) == 0 or k.to_s.casecmp(column.to_s) == 0 then matched = v end end %> -


@@ -51,7 +51,7 @@
<%= yield :update_issue_javascript %>     
+ <%= select_tag "journal_field", raw("") + options_for_select(@headers.map{|header| header.unpack('U*').pack('U*')}), {:disabled => true} %>
    
@@ -73,7 +73,7 @@ <% @headers.each do |column| %> - + <% end %> From 51fe7fa76aa5f3e142cf89c3d76e14cf5a2f7ad6 Mon Sep 17 00:00:00 2001 From: Sho DOUHASHI Date: Thu, 10 Jan 2013 17:35:27 +0900 Subject: [PATCH 4/5] import error --- app/controllers/importer_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/importer_controller.rb b/app/controllers/importer_controller.rb index e941988..43af97f 100644 --- a/app/controllers/importer_controller.rb +++ b/app/controllers/importer_controller.rb @@ -226,6 +226,8 @@ def result end begin + row.each{|k,v| row[k] = v.unpack('U*').pack('U*') if v.kind_of?(String)} + tracker = Tracker.find_by_name(row[attrs_map["tracker"]]) status = IssueStatus.find_by_name(row[attrs_map["status"]]) author = attrs_map["author"] ? user_for_login!(row[attrs_map["author"]]) : User.current From cd811960c06838e1138646970897cccd1bf7088f Mon Sep 17 00:00:00 2001 From: Sho DOUHASHI Date: Thu, 10 Jan 2013 00:24:03 +0900 Subject: [PATCH 5/5] fix encoding error detect encoding fix encode error import error --- app/controllers/importer_controller.rb | 2 ++ app/models/import_in_progress.rb | 25 +++++++++++++++++++++++++ app/views/importer/match.html.erb | 10 +++++----- app/views/importer/result.html.erb | 6 +++++- 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/app/controllers/importer_controller.rb b/app/controllers/importer_controller.rb index e941988..43af97f 100644 --- a/app/controllers/importer_controller.rb +++ b/app/controllers/importer_controller.rb @@ -226,6 +226,8 @@ def result end begin + row.each{|k,v| row[k] = v.unpack('U*').pack('U*') if v.kind_of?(String)} + tracker = Tracker.find_by_name(row[attrs_map["tracker"]]) status = IssueStatus.find_by_name(row[attrs_map["status"]]) author = attrs_map["author"] ? user_for_login!(row[attrs_map["author"]]) : User.current diff --git a/app/models/import_in_progress.rb b/app/models/import_in_progress.rb index 33f35ed..4d27c17 100644 --- a/app/models/import_in_progress.rb +++ b/app/models/import_in_progress.rb @@ -1,5 +1,30 @@ +require 'nkf' class ImportInProgress < ActiveRecord::Base unloadable belongs_to :user belongs_to :project + + before_save :encode_csv_data + + private + def encode_csv_data + return if self.csv_data.blank? + + self.csv_data = self.csv_data + # 入力文字コード + encode = case self.encoding + when "U" + "-W" + when "EUC" + "-E" + when "S" + "-S" + when "N" + "" + else + "" + end + + self.csv_data = NKF.nkf("#{encode} -w", self.csv_data) + end end diff --git a/app/views/importer/match.html.erb b/app/views/importer/match.html.erb index 3c4e9e5..4383254 100644 --- a/app/views/importer/match.html.erb +++ b/app/views/importer/match.html.erb @@ -30,8 +30,8 @@ <% matched = '' @attrs.each do |k,v| if v.to_s.casecmp(column.to_s.sub(" ") {|sp| "_" }) == 0 or k.to_s.casecmp(column.to_s) == 0 then matched = v end end %> -


@@ -51,7 +51,7 @@
<%= yield :update_issue_javascript %>     
+ <%= select_tag "journal_field", raw("") + options_for_select(@headers.map{|header| header.unpack('U*').pack('U*')}), {:disabled => true} %>
    
@@ -73,7 +73,7 @@
<%= column %><%= column.unpack('U*').pack('U*') %>
<% @headers.each do |column| %> - + <% end %> diff --git a/app/views/importer/result.html.erb b/app/views/importer/result.html.erb index 1c17ef7..84a3b29 100644 --- a/app/views/importer/result.html.erb +++ b/app/views/importer/result.html.erb @@ -23,7 +23,11 @@ <% @failed_issues.each do |id, issue| -%> "> - <% issue.each do |column| %><%= content_tag 'td', column[1] %><% end %> + <% issue.each do |column| %> + <%- data = column[1] %> + <%- data = data.unpack('U*').pack('U*') if data.is_a?(String) -%> + <%= content_tag 'td', data %> + <% end %> <% end %>
<%= column %><%= column.unpack('U*').pack('U*') %>
<%= id %>