Project

General

Profile

Defect #44603 ยป 0001-Fix-CSV-import-misdetecting-apostrophes-in-field-val.patch

Go MAEDA, 2026-10-13 11:13

View differences:

app/models/import.rb
73 73
        separator = [',', ';'].max_by {|sep| content.count(sep)}
74 74
        newline = content.index("\r\n") ? "\r\n" : '' # blank means auto
75
        wrapper = ['"', "'"].max_by {|quote_char| content.count(quote_char)}
75
        wrapper = ['"', "'"].max_by do |quote_char|
76
          sep = Regexp.escape(separator)
77
          quote = Regexp.escape(quote_char)
78
          # Apostrophes in unwrapped fields should not be treated as wrappers
79
          wrapped_field = /(?:\A|#{sep}|\n)#{quote}(?:[^#{quote}]|#{quote}#{quote})*#{quote}(?=#{sep}|\r?\n|\z)/n
80
          content.scan(wrapped_field).size
81
        end
76 82
        guessed_encoding = Redmine::CodesetUtil.guess_encoding(content)
77 83
        encoding =
test/fixtures/files/import_issues_with_apostrophes.csv
1
tracker,subject,description
2
Bug,Can't log in after resetting the password,The login form rejects the new password
3
Bug,Search doesn't find closed issues,Closed issues are missing from the search results
4
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
471 471
    to_test = {
472 472
      'import_issues.csv' => '"',
473 473
      'import_issues_single_quotation.csv' => "'",
474
      'import_issues_with_apostrophes.csv' => '"',
474 475
      # Use '"' as a wrapper for CSV file with no wrappers
475 476
      'import_dates.csv' => '"',
476 477
    }
    (1-1/1)