Skip to content

Conversation

@murataslan1
Copy link

Description

Fixes #6809

When parsing an empty string with skipFirstRow: true, the function was throwing a TypeError because there were no headers to extract. This is inconsistent with parsing an empty string without options, which returns an empty array.

Problem

parse('');                          // [] ✓
parse(' ', { skipFirstRow: true }); // [] ✓
parse('', { skipFirstRow: true });  // TypeError: Cannot parse input: headers must be defined ✗

Solution

Return an empty array when there's no data to parse, instead of throwing an error.

Changes

if (options.skipFirstRow) {
  const head = r.shift();
  if (head === undefined) {
-   throw new TypeError("Cannot parse input: headers must be defined");
+   return [] as ParseResult<ParseOptions, T>;
  }
  headers = head;
}

After

parse('');                          // [] ✓
parse('', { skipFirstRow: true });  // [] ✓

Fixes denoland#6809

When parsing an empty string with `skipFirstRow: true`, the function
was throwing a TypeError because there were no headers to extract.
This is inconsistent with parsing an empty string without options,
which returns an empty array.

This change makes the behavior consistent: empty input returns an
empty array regardless of the `skipFirstRow` option.

Before:
```ts
parse('');                          // [] ✓
parse('', { skipFirstRow: true });  // TypeError ✗
```

After:
```ts
parse('');                          // [] ✓
parse('', { skipFirstRow: true });  // [] ✓
```
@murataslan1 murataslan1 requested a review from kt3k as a code owner December 24, 2025 18:52
@CLAassistant
Copy link

CLAassistant commented Dec 24, 2025

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added the csv label Dec 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CSV parsing: header autodetection fails on empty string

2 participants