mholt / PapaParse

Fast and powerful CSV (delimited text) parser that gracefully handles large files and malformed input
http://PapaParse.com
MIT License
12.57k stars 1.15k forks source link

Papa.parse(): comments donot support newline #1072

Open Joelei opened 4 weeks ago

Joelei commented 4 weeks ago

Here is the input sample:

,A,B
#,"Comment of A have
multi lines",Comment of B
,"Data of A have
multi lines",Data of B

config is:

{
  quoteChar: '"',
  escapeChar: '"',
  header: true,
  comments: '#',
  skipEmptyLines: true,
}

I expect to read correctly a line of data:

[
  {"": '', A: 'Data of A have\nmulti lines', B: 'Data of B'}
]

But it throw "FieldMismatch" error, and the parsed data is:

[
  {"": 'multi lines"', A: 'Comment of B'},
  {"": '', A: 'Data of A have\nmulti lines', B: ' Data of B'}
]

If change the sample to this:

,A,B
#,Comment of A,Comment of B
,"Data of A have
multi lines",Data of B

This sample can be parsed correctly.

Does that mean parser doesn't support newline in comment lines?

If not, how can I get the result I want?

Joelei commented 3 weeks ago

Relative disscussion:

1031