mholt / PapaParse

Fast and powerful CSV (delimited text) parser that gracefully handles large files and malformed input
http://PapaParse.com
MIT License
12.54k stars 1.15k forks source link

Papaparse is missing fields #760

Closed innocentdiaz closed 4 years ago

innocentdiaz commented 4 years ago

I'm currently using Papaparse(Version 5) to parse a CSV file uploaded by the user. There are no transformations being made to the file, as it is handed directly to Papaparse, who runs the following code:

Papa.parse(file, {
        // we always assume line one are the headers
        header: true,
        skipEmptyLines: true,
        complete: (data) => resolve(data),
        error: error => {
            reject(error.message);
        },
    });

When I upload the CSV (contents shown below!), and read a console.log of the result Papaparse returns, I get the following object:

{
  "data": [
    {
      "WorkPhone6": "WP6",
      "WorkPhone5": "WP5",
      "WorkPhone1": "WP1",
      "WorkPhone2": "WP2",
      "WorkPhone4": "WP4"
    },
    {
      "WorkPhone6": "WP6",
      "WorkPhone5": "WP5",
      "WorkPhone1": "WP1",
      "WorkPhone2": "WP2",
      "WorkPhone4": "WP4"
    }
  ],
  "meta": {
    "delimiter": ",",
    "linebreak": "\n",
    "aborted": false,
    "truncated": false,
    "cursor": 115,
    "fields": [
      "WorkPhone6",
      "WorkPhone5",
      "WorkPhone1",
      "WorkPhone3",
      "WorkPhone2",
      "WorkPhone4"
    ]
  }
}

In this result, we can clearly see that meta.fields includes "WorkPhone3", but, inside of data, none of the rows include the field "WorkPhone3", even though they all have values for it. This might be a bug with Papaparse. I have included in this issue the exact CSV contnets I am uploading, and posting it as text here:

CSV contents:

WorkPhone6,WorkPhone5,WorkPhone1,WorkPhone3,WorkPhone2,WorkPhone4
WP6,WP5,WP1,WP8,WP2,WP4
WP6,WP5,WP1,WP8,WP2,WP4
innocentdiaz commented 4 years ago

Looks like this issue was actually coming from Redux Saga, and not from Papa!