Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Fatal error: Index out of range" when both ',' and '\n' are within a quoted cell #19

Open
AndrewBennet opened this issue Apr 14, 2017 · 2 comments

Comments

@AndrewBennet
Copy link

AndrewBennet commented Apr 14, 2017

I get an index out of range error when I try to import a CSV file which has both a newline and a comma within a single (quoted) cell. It does not crash when I only have a newline, or I only have a comma.

See this Swift Playground for a full reproduction of the error. The failing code is also copied below:

let csvFileWithCommaAndNewline = "Column 1,Column 2,Column 3\n"
    + "cell 1.1,cell 1.2,cell 1.3\n"
    + "cell 2.1,\"cell 2.2, with comma and \n newline\",cell 2.3"

let importerWithCommaAndNewline = CSVImporter<Row>(contentString: csvFileWithCommaAndNewline)
importerWithCommaAndNewline.importRecords(structure: {print($0)}, recordMapper: {
    return Row(cell1: $0["Column 1"]!, cell2: $0["Column 2"]!, cell3: $0["Column 3"]!)
})
@Jeehut
Copy link
Member

Jeehut commented Apr 15, 2017

Thank you for reporting this, I will have a look at this shortly. If you need it right away, feel free to fix it yourself and provide a pull request. Just make sure that you write a test for this (you already have your example) so this stays fixed in future releases.

@Agnakaraara
Copy link

This is pretty serious issue. Fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants