shystruk/csv-file-validator

Last required header is skipped by validation

Rizvanchos opened this issue · 2 comments

Validation doesn't work correctly for the following case:

Steps to reproduce:

  1. CSV file should contain the following headers: "Name,Surname,Age"
  2. Prepare file with content "Name,Surname"
  3. Validation CSV

Actual result:
No validation errors

Expected result:
Validation error that "Age" header is missing

Please note that the validation will work correctly for the headers with the comma: "Name,Surname,"

Dev notes:
It seems this is because of the row.forEach cycle. Without the comma, the array will contain 2 entries (headers config contains 3 entries), but because of the process is based on row entries instead of headers config, it will never check for the absence of the required headers.

image

@Rizvanchos please share a .csv file

@shystruk , thanks for the reply! Here is the sample CSV
students.csv

We need to show an error message when headers are invalid and this is the case when the last header is completely absent.
It will work with the current code in the case in the end there is a comma.