mafintosh / mafintosh/csv-parser

strict: false - headers lost after row with wrong number of columns

Open
#150 4 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

c³ ⋅ PR welcome
Dominant language
JavaScript
Stars
1.5k
Forks
143
PR merge metrics
No merged PRs in 30d

Description

* Operating System: MacOS 10.14.6
* Node Version: v12.11.1
* NPM Version: 6.11.3
* csv-parser Version: 2.3.1

### Expected Behavior

headers created with "mapHeaders" should be used for all valid records, even for records with to many or to less columns

### Actual Behavior

* when a line contains more columns than headers the broken record is returned with indexed keys.
* any valid line following the broken line is returned with indexed key and not with the headers

### How Do We Reproduce?
https://github.com/aheissenberger/csv-parser?organization=aheissenberger&organization=aheissenberger

```
1 test failed

strictNo › strictNo

/Users/ah/SVN-Checkouts/DEV/csv-parser/test/strictNo.test.js:9

8: const headersLastLine = Object.keys(lines[2])
9: t.deepEqual(headersFirstLine, headersLastLine)
10: t.false(err, 'no err')

Difference:

[
- 'a',
+ '0',
- 'b',
+ '1',
- 'c',
+ '2',
]
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with test/strictNo.test.js and reproduce the failing assertion for the record after a row with too many columns. Trace the parser behavior that follows the malformed row; done means strict:false preserves the mapHeaders keys for subsequent valid records without producing an error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.