shystruk/csv-file-validator

No error detected when there is mismatch between fields and headers

VarunDelft opened this issue · 4 comments

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.

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

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".

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?

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