Skip to content

Commit

Permalink
fix: correctly handle edge case [ZEND-4744]
Browse files Browse the repository at this point in the history
  • Loading branch information
2wce committed Mar 6, 2024
1 parent 63b4725 commit ea50504
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/rich-text-plain-text-renderer/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Block, Node, Inline, helpers } from '@contentful/rich-text-types';
import { Block, Inline, Node, helpers } from '@contentful/rich-text-types';

/**
* Returns the text value of a rich text document.
Expand All @@ -10,7 +10,7 @@ export function documentToPlainTextString(
rootNode: Block | Inline,
blockDivisor: string = ' ',
): string {
if (!rootNode || !rootNode.content) {
if (!rootNode || !rootNode.content || !Array.isArray(rootNode.content)) {
/**
* Handles edge cases, such as when the value is not set in the CMA or the
* field has not been properly validated, e.g. because of a user extension.
Expand All @@ -20,6 +20,7 @@ export function documentToPlainTextString(
*/
return '';
}

/**
* Algorithm notes: We only want to apply spacing when a node is part of a
* sequence. This is tricky because nodes can often be deeply nested within
Expand Down

0 comments on commit ea50504

Please sign in to comment.