Defect #41434 » 41434-csv-crlf.patch
| 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 = setting['newline'].to_s
|
||
|
csv_options[:row_sep] = newline if newline.present?
|
||
|
wrapper = settings['wrapper'].to_s
|
||
|
csv_options[:quote_char] = wrapper if wrapper.size == 1
|
||