Feature #39511 ยป 39511.patch
| app/models/import.rb | ||
|---|---|---|
| 65 | 65 | |
| 66 | 66 |
def set_default_settings(options={})
|
| 67 | 67 |
separator = lu(user, :general_csv_separator) |
| 68 |
wrapper = '"' |
|
| 68 | 69 |
encoding = lu(user, :general_csv_encoding) |
| 69 | 70 |
if file_exists? |
| 70 | 71 |
begin |
| 71 | 72 |
content = File.read(filepath, 256) |
| 72 | 73 | |
| 73 | 74 |
separator = [',', ';'].max_by {|sep| content.count(sep)}
|
| 75 |
wrapper = ['"', "'"].max_by {|quote_char| content.count(quote_char)}
|
|
| 74 | 76 | |
| 75 | 77 |
guessed_encoding = Redmine::CodesetUtil.guess_encoding(content) |
| 76 | 78 |
encoding = |
| ... | ... | |
| 81 | 83 |
rescue => e |
| 82 | 84 |
end |
| 83 | 85 |
end |
| 84 |
wrapper = '"' |
|
| 85 | 86 | |
| 86 | 87 |
date_format = lu(user, "date.formats.default", :default => "foo") |
| 87 | 88 |
date_format = DATE_FORMATS.first unless DATE_FORMATS.include?(date_format) |
| test/fixtures/files/import_issues_single_quotation.csv | ||
|---|---|---|
| 1 |
priority;subject;description;start_date;due_date;parent;private;progress;custom;version;category;user;estimated_hours;tracker;status;multicustom |
|
| 2 |
High;First;First description;2015-07-08;2015-08-25;;no;;PostgreSQL;;New category;dlopper;1;bug;new;'PostgreSQL, Oracle' |
|
| 3 |
Normal;Child 1;Child description;;;1;yes;10;MySQL;2.0;New category;;2;feature request;new;MySQL |
|
| 4 |
Normal;Child of existing issue;Child description;;;#2;no;20;;2.1;Printing;;3;bug;assigned; |
|
| test/unit/issue_import_test.rb | ||
|---|---|---|
| 463 | 463 |
assert_equal 'CP932', guessed_encoding |
| 464 | 464 |
end |
| 465 | 465 |
end |
| 466 | ||
| 467 |
def test_set_default_settings_should_detect_field_wrapper |
|
| 468 |
to_test = {
|
|
| 469 |
'import_issues.csv' => '"', |
|
| 470 |
'import_issues_single_quotation.csv' => "'", |
|
| 471 |
# Use '"' as a wrapper for CSV file with no wrappers |
|
| 472 |
'import_dates.csv' => '"', |
|
| 473 |
} |
|
| 474 | ||
| 475 |
to_test.each do |file, expected| |
|
| 476 |
import = generate_import(file) |
|
| 477 |
import.set_default_settings |
|
| 478 |
assert_equal expected, import.settings['wrapper'] |
|
| 479 |
end |
|
| 480 |
end |
|
| 466 | 481 |
end |