Skip to content

Commit cfac772

Browse files
swissspidyclaude
andcommitted
Keep the synced pattern LIKE fallback whitespace-safe
Without REGEXP support the fallback only matched `"ref":<id>` and `"ref": <id>`, so `{"ref" : 5151}` was dropped before parsing. Fall back to the coarse `"ref"` marker and let parsed matching check the ID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UWTd5pwpi2xQfDA6mUYkkx
1 parent f1acf8a commit cfac772

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

‎features/block-search.feature‎

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

325+
Scenario: Synced pattern prefilter without REGEXP support still finds unusual JSON spacing
326+
Given a wp-content/mu-plugins/no-regexp.php file:
327+
"""
328+
<?php
329+
add_filter(
330+
'query',
331+
static function ( $query ) {
332+
return "SELECT 'a' REGEXP 'a'" === $query ? 'SELECT 0' : $query;
333+
}
334+
);
335+
"""
336+
And I run `wp eval 'wp_insert_post( [ "post_title" => "Wide ref", "post_status" => "publish", "post_content" => "<!-- wp:block {\"ref\" : 5151} /-->" ] ); wp_insert_post( [ "post_title" => "Other ref", "post_status" => "publish", "post_content" => "<!-- wp:block {\"ref\":51510} /-->" ] ); echo "done";'`
337+
338+
When I run `wp block search --synced-pattern=5151 --post_type=post --field=post_title`
339+
Then STDOUT should be:
340+
"""
341+
Wide ref
342+
"""
343+
325344
Scenario: Prefilter finds pattern names with JSON-escaped slashes
326345
When I run `wp eval 'wp_insert_post( wp_slash( [ "post_title" => "Escaped slash pattern", "post_status" => "publish", "post_content" => "<!-- wp:paragraph {\"metadata\":{\"patternName\":\"my-theme\\/hero\"}} --><p>x</p><!-- /wp:paragraph -->" ] ) ); echo "done";'`
327346
Then STDOUT should be:

‎src/Block_Search_Command.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,8 @@ private function build_rough_post_content_prefilter( $block_name, $block_namespa
524524
$markers[] = '"ref"';
525525
$markers[] = [
526526
'regexp' => '"ref"[[:space:]]*:[[:space:]]*' . $synced_pattern . '([^0-9]|$)',
527-
'fallback' => [ '"ref":' . $synced_pattern, '"ref": ' . $synced_pattern ],
527+
// LIKE cannot allow for arbitrary JSON whitespace, so leave the ID to parsed matching.
528+
'fallback' => '"ref"',
528529
];
529530
}
530531

0 commit comments

Comments
 (0)