Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion features/scaffold-block.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
23 changes: 22 additions & 1 deletion features/scaffold-plugin-tests.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 22 additions & 1 deletion features/scaffold-theme-tests.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions src/Scaffold_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) {
Expand Down