From 6c4731c0fa9e8417c3906b1b1a56877553dad821 Mon Sep 17 00:00:00 2001 From: James Nylen Date: Tue, 23 May 2017 09:33:18 -0400 Subject: [PATCH 1/2] Add failing test --- blocks/api/test/parser.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/blocks/api/test/parser.js b/blocks/api/test/parser.js index 3c8d40868fcc84..889a347d10e9f2 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 ) { From 374de4a73ceefb53fc438038935e3e4ca9504091 Mon Sep 17 00:00:00 2001 From: James Nylen Date: Tue, 23 May 2017 09:33:30 -0400 Subject: [PATCH 2/2] Fix parsing empty post content with TinyMCE --- blocks/api/parser.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blocks/api/parser.js b/blocks/api/parser.js index 5b1e16f767941f..4bda5ecf86efbe 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();