Project

General

Profile

Actions

Feature #39511

closed

Auto-detection of field wrapper type when importing CSV file

Added by Go MAEDA 8 months ago. Updated 7 months ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Importers
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed

Description

In the CSV import settings, there are four fields that you have to set. Of these, the field separator and file encoding are auto-detected.

In addition to these, I think the field wrapper could also be auto-detected, using a similar logic to that of the field separator's auto-detection.

diff --git a/app/models/import.rb b/app/models/import.rb
index fe3f24fab..2674606bb 100644
--- a/app/models/import.rb
+++ b/app/models/import.rb
@@ -65,12 +65,14 @@ class Import < ActiveRecord::Base

   def set_default_settings(options={})
     separator = lu(user, :general_csv_separator)
+    wrapper = '"'
     encoding = lu(user, :general_csv_encoding)
     if file_exists?
       begin
         content = File.read(filepath, 256)

         separator = [',', ';'].max_by {|sep| content.count(sep)}
+        wrapper = ['"', "'"].max_by {|quote_char| content.count(quote_char)}

         guessed_encoding = Redmine::CodesetUtil.guess_encoding(content)
         encoding =
@@ -81,7 +83,6 @@ class Import < ActiveRecord::Base
       rescue => e
       end
     end
-    wrapper = '"'

     date_format = lu(user, "date.formats.default", :default => "foo")
     date_format = DATE_FORMATS.first unless DATE_FORMATS.include?(date_format)

Files

39511.patch (2.38 KB) 39511.patch Go MAEDA, 2023-11-04 01:56
Actions #1

Updated by Go MAEDA 8 months ago

Here is a patch.

Actions #2

Updated by Go MAEDA 7 months ago

  • Target version set to 6.0.0

Setting the target version to 6.0.0.

Actions #3

Updated by Go MAEDA 7 months ago

  • Status changed from New to Closed
  • Assignee set to Go MAEDA
  • Resolution set to Fixed

Committed the patch.

Actions

Also available in: Atom PDF