Skip to content

Commit 51a8980

Browse files
committed
prevent nonworking gutenberg block
1 parent 1a40d1b commit 51a8980

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

features/scaffold-block.feature

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ Feature: WordPress block code scaffolding
3131
Error: Can't find 'unknown' plugin.
3232
"""
3333

34+
Scenario: Scaffold a block for an invalid plugin slug
35+
When I run `wp scaffold plugin plugin.name.with.dots`
36+
And I try `wp scaffold block some-block --plugin=plugin.name.with.dots`
37+
Then STDERR should contain:
38+
"""
39+
Error: Invalid plugin name specified.
40+
"""
41+
3442
Scenario: Scaffold a block for a specific plugin
3543
When I run `wp scaffold block the-green-mile --plugin=movies`
3644
Then the {PLUGIN_DIR}/blocks/the-green-mile.php file should exist
@@ -175,3 +183,4 @@ Feature: WordPress block code scaffolding
175183
"""
176184
plugins_url
177185
"""
186+

src/Scaffold_Command.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,12 @@ public function block( $args, $assoc_args ) {
289289
'theme' => false,
290290
) );
291291

292+
if ( isset( $control_args['plugin'] ) ) {
293+
if ( ! preg_match( '/^[A-Za-z0-9\-]*$/', $control_args['plugin'] ) ) {
294+
WP_CLI::error( "Invalid plugin name specified. Block work only if the plugin name contains lowercase alphanumeric characters or dashes" );
295+
}
296+
}
297+
292298
$data['namespace'] = $control_args['plugin'] ? $control_args['plugin'] : $this->get_theme_name( $control_args['theme'] );
293299
$data['machine_name'] = $this->generate_machine_name( $slug );
294300
$data['plugin'] = $control_args['plugin'] ? true : false;

0 commit comments

Comments
 (0)