Skip to content

Invalid parsing when quote is escaped inside quoted column containing delimiter #318

@mayorandrew

Description

@mayorandrew

I have noticed that the following csv is parsed incorrectly:

"c1"|"c2"|"c3"
"1"|"{2\"|3}"|"4"

The following code:

csv({delimiter:'|', escape: '\\', quote: '"'})
.fromString(`"c1"|"c2"|"c3"\n"1"|"{2\\"|3}"|"4"`)
.then((d) => console.log(d))

results in printing:

[ { c1: '1', c2: '"{2\\"', c3: '3}"', field4: '4' } ]

while the expected result is:

[ { c1: '1', c2: '{2"|3}', c3: '4' } ]

I noticed that it only happens when both escaped quote and delimiter are contained inside quoted column, i.e. the following csvs are parsed correctly:

"c1"|"c2"|"c3"
"1"|"{2|3}"|"4"

=>

[ { c1: '1', c2: '{2|3}', c3: '4' } ]
"c1"|"c2"|"c3"
"1"|"{2\"3}"|"4"

=>

[ { c1: '1', c2: '{2"3}', c3: '4' } ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions