Feature #39511 ยป 39511.patch
| app/models/import.rb | ||
|---|---|---|
|
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 =
|
||
| ... | ... | |
|
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)
|
||
| test/fixtures/files/import_issues_single_quotation.csv | ||
|---|---|---|
|
priority;subject;description;start_date;due_date;parent;private;progress;custom;version;category;user;estimated_hours;tracker;status;multicustom
|
||
|
High;First;First description;2015-07-08;2015-08-25;;no;;PostgreSQL;;New category;dlopper;1;bug;new;'PostgreSQL, Oracle'
|
||
|
Normal;Child 1;Child description;;;1;yes;10;MySQL;2.0;New category;;2;feature request;new;MySQL
|
||
|
Normal;Child of existing issue;Child description;;;#2;no;20;;2.1;Printing;;3;bug;assigned;
|
||
| test/unit/issue_import_test.rb | ||
|---|---|---|
|
assert_equal 'CP932', guessed_encoding
|
||
|
end
|
||
|
end
|
||
|
def test_set_default_settings_should_detect_field_wrapper
|
||
|
to_test = {
|
||
|
'import_issues.csv' => '"',
|
||
|
'import_issues_single_quotation.csv' => "'",
|
||
|
# Use '"' as a wrapper for CSV file with no wrappers
|
||
|
'import_dates.csv' => '"',
|
||
|
}
|
||
|
to_test.each do |file, expected|
|
||
|
import = generate_import(file)
|
||
|
import.set_default_settings
|
||
|
assert_equal expected, import.settings['wrapper']
|
||
|
end
|
||
|
end
|
||
|
end
|
||