Project

General

Profile

Actions

Defect #44603

open

Field wrapper is wrongly detected as a single quote when importing a CSV file that contains apostrophes

Defect #44603: Field wrapper is wrongly detected as a single quote when importing a CSV file that contains apostrophes

Added by Go MAEDA about 1 month ago. Updated 27 days ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Importers
Resolution:
Affected version:

Description

The CSV import detects the field wrapper automatically (#39511). However, when a CSV file has no wrapped fields and some values contain apostrophes, the wrapper is wrongly detected as a single quote, and the file cannot be parsed with that setting.

To reproduce the problem, save the following content as a CSV file and upload it on the user import page. "Single quote" is selected as the field wrapper, although "Double quote" is expected.

login,firstname,lastname,mail
jobrien,John,O'Brien,jobrien@example.net
dwilliams,De'Andre,Williams,dwilliams@example.net
soconnor,Sean,O'Connor,soconnor@example.net

This happens because Import#set_default_settings chooses the wrapper by comparing how many times " and ' appear at the beginning of the file. The file above contains no double quotes and three apostrophes.

wrapper = ['"', "'"].max_by {|quote_char| content.count(quote_char)}

The attached patch fixes this by counting only the quote characters that actually wrap a field, that is, those placed at both ends of a field. When neither character wraps any field, the double quote is still used, as before.


Files


Related issues 1 (0 open — 1 closed)

Related to Redmine - Feature #39511: Auto-detection of field wrapper type when importing CSV fileClosedGo MAEDAActions

Updated by Go MAEDA about 1 month ago Actions #1

  • Related to Feature #39511: Auto-detection of field wrapper type when importing CSV file added

Updated by Go MAEDA about 1 month ago Actions #2

  • Affected version set to 6.0.0

Updated by Go MAEDA about 1 month ago Actions #3

  • Target version changed from Candidate for next minor release to 6.1.6

Setting the target version to 6.1.6.

Updated by Go MAEDA 27 days ago Actions #4

  • Target version changed from 6.1.6 to Candidate for next minor release
Actions

Also available in: PDF Atom