Project

General

Profile

Defect #41434 » 0001-CSV-import-fails-with-error-for-quoted-fields-contai.patch

Go MAEDA, 2026-02-16 14:48

View differences:

app/models/import.rb
content = read_file_head
separator = [',', ';'].max_by {|sep| content.count(sep)}
newline = content.index("\r\n") ? "\r\n" : '' # blank means auto
wrapper = ['"', "'"].max_by {|quote_char| content.count(quote_char)}
guessed_encoding = Redmine::CodesetUtil.guess_encoding(content)
......
self.settings.merge!(
'separator' => separator,
'newline' => newline,
'wrapper' => wrapper,
'encoding' => encoding,
'date_format' => date_format,
......
csv_options[:encoding] = 'bom|UTF-8' if csv_options[:encoding] == 'UTF-8'
separator = settings['separator'].to_s
csv_options[:col_sep] = separator if separator.size == 1
newline = settings['newline'].to_s
csv_options[:row_sep] = newline unless newline.empty?
wrapper = settings['wrapper'].to_s
csv_options[:quote_char] = wrapper if wrapper.size == 1
test/fixtures/files/import_crlf_with_newline_in_quoted_header.csv
plain_header,"quoted_header
contains_LF"
foo,bar
test/functional/imports_controller_test.rb
assert_select 'div#flash_error', /The file is not a CSV file or does not match the settings below \([[:print:]]+\)/
end
def test_post_settings_with_crlf_and_newline_in_quoted_header_should_not_fail
import = new_record(Import) do
post(
:create,
:params => {
:type => 'IssueImport',
:file => uploaded_test_file('import_crlf_with_newline_in_quoted_header.csv', 'text/csv')
}
)
assert_response :found
end
assert_equal "\r\n", import.settings['newline']
post(
:settings,
:params => {
:id => import.to_param,
:import_settings => {
:separator => ',',
:wrapper => '"',
:encoding => 'UTF-8'
}
}
)
assert_response :found
import.reload
assert_equal 1, import.total_items
end
def test_post_settings_with_no_data_row_should_display_error
import = generate_import('import_issues_no_data_row.csv')
(5-5/5)