Skip to content

Commit f6ea8fc

Browse files
committed
Fix Copilot findings
1 parent 6f63e3a commit f6ea8fc

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ wp block
2525
$ wp block type list
2626

2727
# Find posts that use a rounded block style
28-
$ wp block search --style=rounded
28+
$ wp block search --style=rounded
2929

3030
# Get a specific block pattern
3131
$ wp block pattern get my-theme/hero

‎src/Block_Command.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
* # List all registered block types
1313
* $ wp block type list
14-
14+
*
1515
* # Find posts by block usage
1616
* $ wp block search --block=core/button
1717
*

‎src/Block_Search_Command.php‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,7 @@ private function flatten_blocks( array $blocks, $ancestor_pattern_name = '' ) {
453453
$flat_blocks[] = $block;
454454

455455
if ( ! empty( $block['innerBlocks'] ) ) {
456-
foreach ( $this->flatten_blocks( $block['innerBlocks'], $block_pattern_name ) as $inner_block ) {
457-
$flat_blocks[] = $inner_block;
458-
}
456+
$flat_blocks = array_merge( $flat_blocks, $this->flatten_blocks( $block['innerBlocks'], $block_pattern_name ) );
459457
}
460458
}
461459

@@ -480,10 +478,14 @@ private function matches_style_filter( array $block, $style_name ) {
480478
$class_name = $block['attrs']['className'];
481479
}
482480

483-
if ( false !== strpos( $class_name, 'is-style-' . $style_name ) ) {
481+
$needle = 'is-style-' . $style_name;
482+
if ( 1 === preg_match( '/(^|\\s)' . preg_quote( $needle, '/' ) . '(\\s|$)/', $class_name ) ) {
484483
return true;
485484
}
486485

487-
return ! empty( $block['innerHTML'] ) && false !== strpos( $block['innerHTML'], 'is-style-' . $style_name );
486+
return ! empty( $block['innerHTML'] ) && 1 === preg_match(
487+
"/(^|[\\s\"'])" . preg_quote( $needle, '/' ) . "([\\s\"']|$)/",
488+
$block['innerHTML']
489+
);
488490
}
489491
}

0 commit comments

Comments
 (0)