Skip to content

CSVParser does not properly handle multiline CSV entries #5

@danypype

Description

@danypype

CSV standard RFC 4180, page 2 states:

  1. Fields containing line breaks (CRLF), double quotes, and commas should be enclosed in double-quotes. For example:
"aaa","b CRLF
bb","ccc" CRLF
zzz,yyy,xxx

However, when we run this:
~/test_file.csv:

hotel_name,address,star_rating
"County Hall","Westminster Bridge Road
London",4
"St. Ermin's Hotel","2 Caxton Street London",5

~/csv_parser_test.js

const CSVParser = require('./csv-parser');
const parser = new CSVParser({
  sourceFilePath: 'test_file.csv'
}, {
  name: 'hotel_name',
  address: 'address',
  stars: 'star_rating',
});

parser.on('object', (hotel, next) => {
  console.log(hotel);
  process.nextTick(next);
});
parser.start();

We get 3 objects back:

$ node csv_parser_test.js
{ name: '"County Hall"',
  address: '"Westminster Bridge Road',
  stars: undefined }
{ name: 'London"', address: '4', stars: undefined }
{ name: '"St. Ermin\'s Hotel"',
  address: '"2 Caxton Street London"',
  stars: '5' }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions