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

Escape comma inside a column #346

Open
jkevinturado opened this issue Jun 17, 2022 · 13 comments
Open

Escape comma inside a column #346

jkevinturado opened this issue Jun 17, 2022 · 13 comments

Comments

@jkevinturado
Copy link

Hi,

My raw data got a comma from a certain field, While I'm parsing the data it cause me to have a new column instead. How do you escape a comma inside a column to prevent this?

Here is a example of raw csv data

"test@email.org, test2@mail.com",email.org,none,bad
now the data returned from me is

[test@email.org,test2@mail.com,email.org,none,bad]

What I'm expecting is

["test@email.org,test2@mail.com",email.org,none,bad]

I tried to escape the comma by escape: '\\,' but it doesn't help

@wdavidw
Copy link
Member

wdavidw commented Jun 17, 2022

My understanding is: "test@email.org, test2@mail.com",email.org,none,bad is the source and you expect ["test@email.org,test2@mail.com",email.org,none,bad], right ?

This seems like the default behavior to me. I checked and can confirm with our online tool

image

image

@jkevinturado
Copy link
Author

Yes that is correct, is this a default config?

@jkevinturado
Copy link
Author

Hi,

I am escaping the double quotes and I need to escape that because some of the fields do have double quotes inside the field for example:

image

So this is my config btw:

image

@jkevinturado
Copy link
Author

Hi, I'm using the default config.

Now the error is:
Invalid Closing Quote: got "d" at line 1 instead of delimiter, record delimiter, trimable character (if activated) or comment

Because I have this double quote inside a field:
image

@wdavidw
Copy link
Member

wdavidw commented Jun 20, 2022

The screenshot I shared use the default config.

@wdavidw
Copy link
Member

wdavidw commented Jun 20, 2022

Please share a minimalist and complete example for additionnal help.

@jkevinturado
Copy link
Author

Hi,

I was using the default config, I'm okay with the first issue which has the comma inside, now I have double quotes inside the field and it says
image

Here is the input please focus on the 2nd line which has the double quotes inside the field

image

@wdavidw
Copy link
Member

wdavidw commented Jun 20, 2022

Honestly, I don't think there is much we can do to handle such a scenario. The first quote place the parser in quoting mode and second quote is not escape which makes the field invalid

@jkevinturado
Copy link
Author

I can actually escape the comma, using the option escape. Can I escape multiple characters?

I've tried escape: ',"' but I didn't work

@wdavidw
Copy link
Member

wdavidw commented Jun 20, 2022

Yes, escape may be composed of multiple characters: https://github.com/adaltas/node-csv/blob/master/packages/csv-parse/test/option.escape.coffee#L69-L79

@jkevinturado
Copy link
Author

how?

@wdavidw
Copy link
Member

wdavidw commented Jun 20, 2022

Look at the tests with the link above, I based my answer on them.

@jkevinturado
Copy link
Author

it didn't work, I think the link above you've provided will work if the character is contiguous.

Mine have to escape comma and double quotes just like this escape: ',"' unfortunately this doesn't work also as well

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

2 participants