Skip to content

Commit

Permalink
fix(utils): getplaintext empty edgecase
Browse files Browse the repository at this point in the history
  • Loading branch information
BJvdA committed Jun 19, 2021
1 parent 5bf1f57 commit 3af4373
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/utils/__tests__/getPlainText.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,14 @@ It is a paradisematic country, in which roasted parts of sentences fly into your

expect(result).toBe('');
});

it('should return an empty string from empty richtext paragraph', async () => {
const rich = {
type: 'doc',
content: [{ type: 'paragraph' }],
};
const result = getPlainText(rich);

expect(result).toBe('');
});
});
6 changes: 3 additions & 3 deletions src/utils/getPlainText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ const renderNode = (node: any, addNewlines: boolean) => {
NODE_BR,
].includes(node.type)
) {
return `${renderNodes(node.content, addNewlines)}${
addNewlines ? '\n\n' : ' '
}`;
return node.content?.length
? `${renderNodes(node.content, addNewlines)}${addNewlines ? '\n\n' : ' '}`
: '';
}

return null;
Expand Down

1 comment on commit 3af4373

@vercel
Copy link

@vercel vercel bot commented on 3af4373 Jun 19, 2021

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.