Skip to content

Commit

Permalink
Fix parsing empty post content with TinyMCE (#875)
Browse files Browse the repository at this point in the history
  • Loading branch information
nylen committed May 23, 2017
1 parent 38427b6 commit 69d7c94
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions blocks/api/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -208,7 +208,7 @@ export function parseWithTinyMCE( content ) {
currentNode = currentNode.next;
contentBetweenBlocks.append( toAppend );
}
} while ( currentNode );
}

flushContentBetweenBlocks();

Expand Down
6 changes: 6 additions & 0 deletions blocks/api/test/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down

0 comments on commit 69d7c94

Please sign in to comment.