diff --git a/features/scaffold-block.feature b/features/scaffold-block.feature index 27874f47..868be36e 100644 --- a/features/scaffold-block.feature +++ b/features/scaffold-block.feature @@ -31,7 +31,7 @@ Feature: WordPress block code scaffolding """ Scenario: Scaffold a block for an invalid plugin slug - When I run `wp scaffold plugin plugin.name.with.dots` + When I try `wp scaffold plugin plugin.name.with.dots` And I try `wp scaffold block some-block --plugin=plugin.name.with.dots` Then STDERR should contain: """ diff --git a/features/scaffold-plugin-tests.feature b/features/scaffold-plugin-tests.feature index 95fee4ca..2ab4738e 100644 --- a/features/scaffold-plugin-tests.feature +++ b/features/scaffold-plugin-tests.feature @@ -236,7 +236,28 @@ Feature: Scaffold plugin unit tests When I try `wp scaffold plugin-tests ../` Then STDERR should be: """ - Error: Invalid plugin slug specified. The target directory '{RUN_DIR}/wp-content/plugins/../' is not in '{RUN_DIR}/wp-content/plugins'. + Error: Invalid plugin slug specified. The slug can only contain alphanumeric characters and dashes. + """ + And the return code should be 1 + + When I try `wp scaffold plugin-tests my-plugin/` + Then STDERR should be: + """ + Error: Invalid plugin slug specified. The slug can only contain alphanumeric characters and dashes. + """ + And the return code should be 1 + + When I try `wp scaffold plugin-tests my-plugin\\` + Then STDERR should be: + """ + Error: Invalid plugin slug specified. The slug can only contain alphanumeric characters and dashes. + """ + And the return code should be 1 + + When I try `wp scaffold plugin-tests my_plugin` + Then STDERR should be: + """ + Error: Invalid plugin slug specified. The slug can only contain alphanumeric characters and dashes. """ And the return code should be 1 diff --git a/features/scaffold-theme-tests.feature b/features/scaffold-theme-tests.feature index 7a4f2ac5..a55b06a6 100644 --- a/features/scaffold-theme-tests.feature +++ b/features/scaffold-theme-tests.feature @@ -215,7 +215,28 @@ Feature: Scaffold theme unit tests When I try `wp scaffold theme-tests ../` Then STDERR should be: """ - Error: Invalid theme slug specified. The target directory '{RUN_DIR}/wp-content/themes/../' is not in '{RUN_DIR}/wp-content/themes'. + Error: Invalid theme slug specified. The slug can only contain alphanumeric characters and dashes. + """ + And the return code should be 1 + + When I try `wp scaffold theme-tests t12child/` + Then STDERR should be: + """ + Error: Invalid theme slug specified. The slug can only contain alphanumeric characters and dashes. + """ + And the return code should be 1 + + When I try `wp scaffold theme-tests t12child\\` + Then STDERR should be: + """ + Error: Invalid theme slug specified. The slug can only contain alphanumeric characters and dashes. + """ + And the return code should be 1 + + When I try `wp scaffold theme-tests t12_child` + Then STDERR should be: + """ + Error: Invalid theme slug specified. The slug can only contain alphanumeric characters and dashes. """ And the return code should be 1 diff --git a/src/Scaffold_Command.php b/src/Scaffold_Command.php index e92a032e..3234f70b 100644 --- a/src/Scaffold_Command.php +++ b/src/Scaffold_Command.php @@ -829,6 +829,10 @@ private function scaffold_plugin_theme_tests( $args, $assoc_args, $type ) { if ( in_array( $slug, [ '.', '..' ], true ) ) { WP_CLI::error( "Invalid {$type} slug specified. The slug cannot be '.' or '..'." ); } + // Validate slug contains only alphanumeric characters and dashes. + if ( ! preg_match( '/^[a-zA-Z0-9-]+$/', $slug ) ) { + WP_CLI::error( "Invalid {$type} slug specified. The slug can only contain alphanumeric characters and dashes." ); + } if ( 'theme' === $type ) { $theme = wp_get_theme( $slug ); if ( $theme->exists() ) {