Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing empty post content with TinyMCE #875

Merged
merged 2 commits into from
May 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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