Skip to content

Commit 8e52a63

Browse files
authored
Merge branch 'main' into copilot/fix-theme-activate-issue
2 parents 5835b9a + 5a690ec commit 8e52a63

6 files changed

Lines changed: 46 additions & 6 deletions

File tree

.github/workflows/code-quality.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ on:
66
branches:
77
- main
88
- master
9+
schedule:
10+
- cron: '17 2 * * *' # Run every day on a seemly random time.
911

1012
jobs:
1113
code-quality:

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
}
1313
],
1414
"require": {
15-
"wp-cli/wp-cli": "^2.12"
15+
"wp-cli/wp-cli": "^2.13"
1616
},
1717
"require-dev": {
1818
"wp-cli/extension-command": "^1.2 || ^2",

features/scaffold-block.feature

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ Feature: WordPress block code scaffolding
3131
"""
3232

3333
Scenario: Scaffold a block for an invalid plugin slug
34-
When I run `wp scaffold plugin plugin.name.with.dots`
35-
And I try `wp scaffold block some-block --plugin=plugin.name.with.dots`
34+
When I try `wp scaffold block some-block --plugin=plugin.name.with.dots`
3635
Then STDERR should contain:
3736
"""
3837
Error: Invalid plugin name specified.

features/scaffold-plugin-tests.feature

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,21 @@ Feature: Scaffold plugin unit tests
236236
When I try `wp scaffold plugin-tests ../`
237237
Then STDERR should be:
238238
"""
239-
Error: Invalid plugin slug specified. The target directory '{RUN_DIR}/wp-content/plugins/../' is not in '{RUN_DIR}/wp-content/plugins'.
239+
Error: Invalid plugin slug specified. The slug can only contain alphanumeric characters, underscores, and dashes.
240+
"""
241+
And the return code should be 1
242+
243+
When I try `wp scaffold plugin-tests my-plugin/`
244+
Then STDERR should be:
245+
"""
246+
Error: Invalid plugin slug specified. The slug can only contain alphanumeric characters, underscores, and dashes.
247+
"""
248+
And the return code should be 1
249+
250+
When I try `wp scaffold plugin-tests my-plugin\\`
251+
Then STDERR should be:
252+
"""
253+
Error: Invalid plugin slug specified. The slug can only contain alphanumeric characters, underscores, and dashes.
240254
"""
241255
And the return code should be 1
242256

features/scaffold-theme-tests.feature

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,21 @@ Feature: Scaffold theme unit tests
215215
When I try `wp scaffold theme-tests ../`
216216
Then STDERR should be:
217217
"""
218-
Error: Invalid theme slug specified. The target directory '{RUN_DIR}/wp-content/themes/../' is not in '{RUN_DIR}/wp-content/themes'.
218+
Error: Invalid theme slug specified. The slug can only contain alphanumeric characters, underscores, and dashes.
219+
"""
220+
And the return code should be 1
221+
222+
When I try `wp scaffold theme-tests t12child/`
223+
Then STDERR should be:
224+
"""
225+
Error: Invalid theme slug specified. The slug can only contain alphanumeric characters, underscores, and dashes.
226+
"""
227+
And the return code should be 1
228+
229+
When I try `wp scaffold theme-tests t12child\\`
230+
Then STDERR should be:
231+
"""
232+
Error: Invalid theme slug specified. The slug can only contain alphanumeric characters, underscores, and dashes.
219233
"""
220234
And the return code should be 1
221235

src/Scaffold_Command.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,9 +856,13 @@ private function scaffold_plugin_theme_tests( $args, $assoc_args, $type ) {
856856

857857
if ( ! empty( $args[0] ) ) {
858858
$slug = $args[0];
859+
// Validate slug contains only alphanumeric characters, underscores, and dashes.
859860
if ( in_array( $slug, [ '.', '..' ], true ) ) {
860861
WP_CLI::error( "Invalid {$type} slug specified. The slug cannot be '.' or '..'." );
861862
}
863+
if ( ! preg_match( '/^[a-zA-Z0-9_-]+$/', $slug ) ) {
864+
WP_CLI::error( "Invalid {$type} slug specified. The slug can only contain alphanumeric characters, underscores, and dashes." );
865+
}
862866
if ( 'theme' === $type ) {
863867
$theme = wp_get_theme( $slug );
864868
if ( $theme->exists() ) {
@@ -886,6 +890,13 @@ private function scaffold_plugin_theme_tests( $args, $assoc_args, $type ) {
886890
}
887891
if ( empty( $slug ) ) {
888892
$slug = Utils\basename( $target_dir );
893+
// Validate derived slug as well.
894+
if ( in_array( $slug, [ '.', '..' ], true ) ) {
895+
WP_CLI::error( "Invalid {$type} slug specified. The slug cannot be '.' or '..'." );
896+
}
897+
if ( ! preg_match( '/^[a-zA-Z0-9_-]+$/', $slug ) ) {
898+
WP_CLI::error( "Invalid {$type} slug specified. The slug can only contain alphanumeric characters, underscores, and dashes." );
899+
}
889900
}
890901
}
891902

@@ -1228,7 +1239,7 @@ private static function canonicalize_path( $path ) {
12281239
/**
12291240
* Gets an active theme's name when true provided or the same name otherwise.
12301241
*
1231-
* @param string|bool $theme Theme name or true.
1242+
* @param string|true $theme Theme name or true.
12321243
* @return string
12331244
*/
12341245
private function get_theme_name( $theme ) {

0 commit comments

Comments
 (0)