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

No error detected when there is mismatch between fields and headers #57

Closed
VarunDelft opened this issue May 26, 2021 · 4 comments · Fixed by #62
Closed

No error detected when there is mismatch between fields and headers #57

VarunDelft opened this issue May 26, 2021 · 4 comments · Fixed by #62

Comments

@VarunDelft
Copy link

VarunDelft commented May 26, 2021

Hi,
Given the following CSV:

Header1;
Value1;Value2;

Config:

{
headers: [
{name: 'Header1', inputName: 'header1', required:true},
{name: 'Header2', inputName: 'header2', required:true}
],
isHeaderNameOptional: false
}

I would expect a parse error since there is mismatch between headers and fields. But I don't get any error in the validator response. Is this feature not implemented or am I missing something ?
Thanks.

@shystruk
Copy link
Owner

Hi @VarunDelft,
The header and fields behind this header are not validating.
Can you please describe your use case?

@VarunDelft
Copy link
Author

Hi @shystruk , I am basically trying to check for an incorrectly formatted csv. Sometimes the user forgets to include the delimiters and that results in mismatch of headers and the fields specified under it. In Papa Parse, these errors are detected as FieldMismatch error. You can try this out here: https://www.papaparse.com/demo. Under results.errors you can see the error type and message displayed "Too many fields: expected 2 fields but parsed 3".

@sushieez
Copy link

Hey @shystruk,
I think there might be a logical error in the code that prevents from populating the errors when the source CSV file has less columns than specified in the config, just as in @VarunDelft 's case.
This might be related to lines 62-64 of csv-file-validator.js.
if (row.length < headers.length) { return;}
This should not be the default behaviour, am I right?

@shystruk
Copy link
Owner

shystruk commented Jun 1, 2021

@sushieez make sense, should return an error when fields mismatch

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

Successfully merging a pull request may close this issue.

3 participants