Project

General

Profile

Actions

Defect #44603

open

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

Added by Go MAEDA 2 days ago. Updated about 5 hours ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Importers
Target version:
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

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

Updated by Go MAEDA 2 days ago

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

Updated by Go MAEDA 2 days ago

  • Affected version set to 6.0.0
Actions #3

Updated by Go MAEDA about 5 hours ago

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

Setting the target version to 6.1.6.

Actions

Also available in: Atom PDF