Defect #44603 ยป 0001-Fix-CSV-import-misdetecting-apostrophes-in-field-val.patch
| app/models/import.rb | ||
|---|---|---|
|
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)}
|
||
|
wrapper = ['"', "'"].max_by do |quote_char|
|
||
|
sep = Regexp.escape(separator)
|
||
|
quote = Regexp.escape(quote_char)
|
||
|
# Apostrophes in unwrapped fields should not be treated as wrappers
|
||
|
wrapped_field = /(?:\A|#{sep}|\n)#{quote}(?:[^#{quote}]|#{quote}#{quote})*#{quote}(?=#{sep}|\r?\n|\z)/n
|
||
|
content.scan(wrapped_field).size
|
||
|
end
|
||
|
guessed_encoding = Redmine::CodesetUtil.guess_encoding(content)
|
||
|
encoding =
|
||
| test/fixtures/files/import_issues_with_apostrophes.csv | ||
|---|---|---|
|
tracker,subject,description
|
||
|
Bug,Can't log in after resetting the password,The login form rejects the new password
|
||
|
Bug,Search doesn't find closed issues,Closed issues are missing from the search results
|
||
|
Feature request,Show the user's avatar in the issue list,Display the avatar next to the assignee name
|
||
| test/unit/issue_import_test.rb | ||
|---|---|---|
|
to_test = {
|
||
|
'import_issues.csv' => '"',
|
||
|
'import_issues_single_quotation.csv' => "'",
|
||
|
'import_issues_with_apostrophes.csv' => '"',
|
||
|
# Use '"' as a wrapper for CSV file with no wrappers
|
||
|
'import_dates.csv' => '"',
|
||
|
}
|
||