Repository navigation
Fix unparse crash on null/undefined single-cell rows with skipEmptyLines - #1164
Merged
pokoli merged 2 commits intoOct 8, 2026
Merged
Conversation
When skipEmptyLines is true, unparse detects an empty array row by checking whether its only cell has a length of 0. A null or undefined cell has no length property, so the check threw a TypeError instead of treating the row as empty. Treat null and undefined like an empty string there, matching how they are already serialized as empty cells. Fixes #1163
pokoli
requested changes
Oct 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1163
Problem
With
skipEmptyLines: true,Papa.unparse()throws when an array row has exactly one cell and that cell isnullorundefined:The same crash happens with the
{ data: [...] }input form when nofieldsare given (and with JSON-string input), because those go through the same code path. WithskipEmptyLines: falseor'greedy'there is no crash.Cause
In
serialize(), when there are no header fields andskipEmptyLinesistrue, a row counts as empty when it has one cell and that cell has a length of 0:nullandundefinedhave nolengthproperty, so reading it throws. Other code already treats these values as empty:safe()writesnull/undefinedas empty cells, and the'greedy'check usesjoin(''), which turns them into''.Fix
The
truecheck now counts a singlenullorundefinedcell as empty, the same as'':So
[[null], ['hello']]and[[undefined], ['hello']]now returnhello, the same as[[''], ['hello']]. This is a one-line change. Nothing changes forskipEmptyLines: falseor'greedy', and a single non-string cell like0is still not treated as empty.I also checked the object input forms (array of objects, and
{fields, data}with non-emptyfields). They don't crash: when there's a header,skipEmptyLines: trueonly skips rows with no keys ({}), so this code path never runs. I didn't change their behavior.Tests
I added these cases to
UNPARSE_TESTSintests/test-cases.js:null/undefinedsingle-cell rows are skipped withskipEmptyLines: true(array input){ data: [...] }inputnull/undefinedsingle-cell rows still produce empty lines withskipEmptyLines: falsenull/undefinedsingle-cell rows are skipped withskipEmptyLines: 'greedy'0is not skipped withskipEmptyLines: trueWithout the fix, the first two fail with the TypeError. With the fix:
npm run lintpassesnpm run test-node: 260 passing, 25 pendingnpm run test-mocha-headless-chrome: 264 passing, 8 pendingI didn't regenerate
papaparse.min.js, since the project's history only updates it in version-bump commits.