question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Leading zero-width no-break space in keys

See original GitHub issue
  • Operating System: Mac OS 10.14.5
  • Node Version: 10.15.3
  • NPM Version: 6.9.0
  • csv-parser Version: 2.3.0

Expected Behavior

With a CSV looking like:

name,start_date,end_date
some - name,2019-08-25,2019-12-31
another - name,2019-08-05,2019-12-31

after parsing, accessing row.name should return a string

Actual Behavior

The row property doesn’t actually have name, but rather name preceeded by the utf char 65279, or a zero-width no-break space. I’ve created the CSV by hand, so I have no idea why that character would be in there

How Do We Reproduce?

fs.createReadStream(input_path)
        .pipe(parse())
        .on('data', (data) => console.log(data.name)) // undefined :(
        .on('end', () => {});

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

4reactions
fedpettinellacommented, Mar 13, 2020

I found this issue as well. The CSVs were created using Excel. First saved as xlsx, then as CSV. Printing the JSON.stringify() showed the header as ' USER_NAME' instead of the expected 'USER_NAME'. I wasn’t able to get around this by modifying the CSV file, but I could instead trim the headers using the included mapHeaders function:

.pipe(csv({
    mapHeaders: ({ header, index }) => header.trim()
  }))
1reaction
shellscapecommented, Jul 29, 2019

I’m not a VS Code user, so I’m afraid you’d have to ask those folks. But you can use intermediate tools like https://github.com/sindresorhus/strip-bom and https://github.com/sindresorhus/strip-bom-cli to do that as part of the process.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Type a Zero-width Space for Perfect Line Breaks in ...
The zero-width space lets you handle tables with unpredictable or dynamic widths without breaking things up visually if the line doesn't have to ......
Read more >
Non-breaking space - Wikipedia
Encodings. In Unicode, the Byte order mark (BOM), U+FEFF, may be interpreted as a "zero width no-break space", but is a deprecated alternative...
Read more >
C# writes a ZERO WIDTH NO-BREAK SPACE at the ...
I have a text file that is written in C# using ascii encoding and when I attempt to read the file using a...
Read more >
Variable-width non-breaking space in Word 2016 (including a ...
So far, I found a single solution: typing U+FEFF, then regular space, then U+FEFF again. U+FEFF is "Zero Width No-Break Space", so it...
Read more >
'ZERO WIDTH NO-BREAK SPACE' causes issues with first ...
Specifically, this occurs because the whitespace character is included as part of the string in the header key collection so lookup by that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found