Skip to content

Commit f7ac0ee

Browse files
swissspidyclaude
andcommitted
Start block comment prefilter markers at wp:
The block parser accepts any whitespace after `<!--`, but the block and namespace markers required exactly one space, so content such as `<!-- wp:paragraph -->` never reached parsing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UWTd5pwpi2xQfDA6mUYkkx
1 parent cfac772 commit f7ac0ee

2 files changed

Lines changed: 40 additions & 5 deletions

File tree

‎features/block-search.feature‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,39 @@ Feature: Search posts by block usage
322322
Wide pattern
323323
"""
324324

325+
Scenario: Prefilter finds block comments with extra whitespace after the comment opener
326+
Given I run `wp post delete 1 --force`
327+
328+
When I run `wp eval 'wp_insert_post( [ "post_title" => "Spaced core", "post_status" => "publish", "post_content" => "<!-- wp:paragraph --><p>x</p><!-- /wp:paragraph -->" ] ); wp_insert_post( [ "post_title" => "Spaced custom", "post_status" => "publish", "post_content" => "<!--\twp:my-plugin/spaced /-->" ] ); echo "done";'`
329+
Then STDOUT should be:
330+
"""
331+
done
332+
"""
333+
334+
When I run `wp block search --block=core/paragraph --post_type=post --field=post_title`
335+
Then STDOUT should be:
336+
"""
337+
Spaced core
338+
"""
339+
340+
When I run `wp block search --block-namespace=core --post_type=post --field=post_title`
341+
Then STDOUT should be:
342+
"""
343+
Spaced core
344+
"""
345+
346+
When I run `wp block search --block=my-plugin/spaced --post_type=post --field=post_title`
347+
Then STDOUT should be:
348+
"""
349+
Spaced custom
350+
"""
351+
352+
When I run `wp block search --block-namespace=my-plugin --post_type=post --field=post_title`
353+
Then STDOUT should be:
354+
"""
355+
Spaced custom
356+
"""
357+
325358
Scenario: Synced pattern prefilter without REGEXP support still finds unusual JSON spacing
326359
Given a wp-content/mu-plugins/no-regexp.php file:
327360
"""

‎src/Block_Search_Command.php‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,11 @@ private function build_rough_post_content_prefilter( $block_name, $block_namespa
489489
$markers = [];
490490

491491
if ( null !== $block_name && '' !== $block_name ) {
492+
// The parser accepts any whitespace after `<!--`, so the markers start at `wp:`.
492493
$markers[] = $this->alternatives(
493494
[
494-
'<!-- wp:' . $this->strip_core_block_namespace( $block_name ),
495-
'<!-- wp:' . $block_name,
495+
'wp:' . $this->strip_core_block_namespace( $block_name ),
496+
'wp:' . $block_name,
496497
]
497498
);
498499
}
@@ -699,17 +700,18 @@ private function strip_core_block_namespace( $block_name ) {
699700
* Builds a rough serialized comment marker for a block namespace.
700701
*
701702
* Core blocks omit the namespace in serialized comments, so the safest
702-
* coarse marker for core is the generic block comment prefix.
703+
* coarse marker for core is the generic block comment prefix. Markers start
704+
* at `wp:` because the parser accepts any whitespace after `<!--`.
703705
*
704706
* @param string $block_namespace Requested block namespace.
705707
* @return string
706708
*/
707709
private function build_block_namespace_prefilter_marker( $block_namespace ) {
708710
if ( 'core' === $block_namespace ) {
709-
return '<!-- wp:';
711+
return 'wp:';
710712
}
711713

712-
return '<!-- wp:' . $block_namespace . '/';
714+
return 'wp:' . $block_namespace . '/';
713715
}
714716

715717
/**

0 commit comments

Comments
 (0)