Skip to content

Commit

Permalink
Add check in splitCells to prevent calling trim on undefined (#2372)
Browse files Browse the repository at this point in the history
  • Loading branch information
zbialecki committed Jan 27, 2022
1 parent 8375314 commit ed66bf8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/helpers.js
Expand Up @@ -162,7 +162,7 @@ export function splitCells(tableRow, count) {

// First/last cell in a row cannot be empty if it has no leading/trailing pipe
if (!cells[0].trim()) { cells.shift(); }
if (!cells[cells.length - 1].trim()) { cells.pop(); }
if (cells.length > 0 && !cells[cells.length - 1].trim()) { cells.pop(); }

if (cells.length > count) {
cells.splice(count);
Expand Down
22 changes: 22 additions & 0 deletions test/specs/new/nbsp_following_tables.html
@@ -0,0 +1,22 @@
<table>
<thead>
<tr>
<th>abc</th>
<th>def</th>
</tr>
</thead>
<tbody>
<tr>
<td>bar</td>
<td>foo</td>
</tr>
<tr>
<td>baz</td>
<td>boo</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</tbody>
</table>
5 changes: 5 additions & 0 deletions test/specs/new/nbsp_following_tables.md
@@ -0,0 +1,5 @@
| abc | def |
| --- | --- |
| bar | foo |
| baz | boo |

1 comment on commit ed66bf8

@vercel
Copy link

@vercel vercel bot commented on ed66bf8 Jan 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.