Skip to content

fix: handle undefined head option in toString()#181

Open
ctonneslan wants to merge 1 commit intoAutomattic:v0.4.0from
ctonneslan:fix/head-undefined-crash
Open

fix: handle undefined head option in toString()#181
ctonneslan wants to merge 1 commit intoAutomattic:v0.4.0from
ctonneslan:fix/head-undefined-crash

Conversation

@ctonneslan
Copy link

Summary

Fixes toString() crashing when the Table constructor receives head: undefined.

Problem

const table = new Table({ head: undefined });
table.push(['a', 'b']);
table.toString(); // TypeError: Cannot read properties of undefined (reading 'length')

The head variable on line 89 takes options.head directly without defaulting, so undefined propagates to .length checks on lines 92 and 95.

Fix

Default head to an empty array: options.head || []

This matches the behavior when head is not passed at all (the default options already set head: [] on line 48).

Fixes #178

When the Table constructor receives head: undefined, toString() crashes
with 'Cannot read properties of undefined' because it tries to access
.length on the undefined head value. Default to an empty array.

Fixes Automattic#178
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.toString() throws error when new Table was instanciated with "head" prop as undefined.

1 participant