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

Don't try to parse strings that don't contain blocks #3903

Merged
merged 4 commits into from
Dec 11, 2017
Merged
Changes from 3 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
13 changes: 13 additions & 0 deletions lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ function unregister_block_type( $name ) {
* @return array Array of parsed block objects.
*/
function gutenberg_parse_blocks( $content ) {
/*
* If there are no blocks in the content, return a single block, rather
* than wasting time trying to parse the string.
*/
if ( ! preg_match( '/<!--\s*(wp:|more|noteaser)/', $content ) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use gutenberg_content_has_blocks() here?

return array(
array(
'attrs' => array(),
'innerHTML' => $content,
),
);
}

$parser = new Gutenberg_PEG_Parser;
return $parser->parse( _gutenberg_utf8_split( $content ) );
}
Expand Down