diff --git a/blocks/api/parser.js b/blocks/api/parser.js index 5b1e16f767941..4bda5ecf86efb 100644 --- a/blocks/api/parser.js +++ b/blocks/api/parser.js @@ -161,7 +161,7 @@ export function parseWithTinyMCE( content ) { flushContentBetweenBlocks(); let currentNode = tree.firstChild; - do { + while ( currentNode ) { if ( currentNode.name === 'wp-block' ) { // Set node type to document fragment so that the TinyMCE // serializer doesn't output its markup @@ -208,7 +208,7 @@ export function parseWithTinyMCE( content ) { currentNode = currentNode.next; contentBetweenBlocks.append( toAppend ); } - } while ( currentNode ); + } flushContentBetweenBlocks(); diff --git a/blocks/api/test/parser.js b/blocks/api/test/parser.js index 3c8d40868fcc8..889a347d10e9f 100644 --- a/blocks/api/test/parser.js +++ b/blocks/api/test/parser.js @@ -173,6 +173,12 @@ describe( 'block parser', () => { expect( parsed[ 0 ].uid ).to.be.a( 'string' ); } ); + it( 'should parse empty post content', () => { + const parsed = parse( '' ); + + expect( parsed ).to.eql( [] ); + } ); + it( 'should parse the post content, ignoring unknown blocks', () => { registerBlock( 'core/test-block', { attributes: function( rawContent ) {