node-csvtojson icon indicating copy to clipboard operation
node-csvtojson copied to clipboard

Several comma's prevent csv() identify fields in text

Open svakulenko opened this issue 2 years ago • 0 comments

Hello

Issue I notice that several comma's in text avoid parser to split text correctly between fields. Reproduced with version 2.0.0 and older versions of library.

Bootcode:

const options = {
            noheader: true,
            delimiter: [",",";"]        
        }
let responseDataModified = fs.readFileSync("myfile_working_example.csv", 'utf8')

csv(options)
        .fromString(responseDataModified)
        .subscribe(function(json){
            let stringed = JSON.stringify(json)
            console.log(JSON.stringify(json)
            }
        })

myfile_working_example.csv

"MY_TEXT_KEY";"Content of My Text.";"C'est le content, le content du text."

myfile_example_with_bug.csv

"MY_TEXT_KEY";"Content of My Text.";"C'est le content, le, content du text."

Description of issue

Launch parser with myfile_working_example.csv file will generate output with 3 fields and its what we expect.

output using myfile_working_example.csv:

{"field1":"MY_TEXT_KEY","field2":"Content of My Text.","field3":"C'est le content, le content du text."}

However, launch parser with myfile_example_with_bug.csv file will generate output where fields are not separate and merged in single field which is error. The reason is added comma in le, content part of text

output using myfile_example_with_bug.csv:

{"field1":"MY_TEXT_KEY\";\"Content of My Text.\";\"C'est le content, le, content du text."}

to note: if delimiter will not contain comma, it will split correctly the text with myfile_example_with_bug.csv. However, as API of delimiter its array of items, it looks like border condition that provoke bug.

Thank you

svakulenko avatar Jul 12 '23 15:07 svakulenko