Skip to content

Commit 69cbb43

Browse files
authored
Merge branch 'main' into try/322-refresh
2 parents 41b8fe0 + 5a690ec commit 69cbb43

6 files changed

Lines changed: 47 additions & 7 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: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Feature: Scaffold theme unit tests
88
When I run `wp theme path`
99
Then save STDOUT as {THEME_DIR}
1010

11-
@require-php-7.0 @less-than-php-7.2 @require-mysql
11+
@require-php-7.0 @require-mysql
1212
Scenario: Scaffold theme tests
1313
When I run `wp scaffold theme-tests t12child`
1414
Then STDOUT should not be empty
@@ -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
@@ -828,9 +828,13 @@ private function scaffold_plugin_theme_tests( $args, $assoc_args, $type ) {
828828

829829
if ( ! empty( $args[0] ) ) {
830830
$slug = $args[0];
831+
// Validate slug contains only alphanumeric characters, underscores, and dashes.
831832
if ( in_array( $slug, [ '.', '..' ], true ) ) {
832833
WP_CLI::error( "Invalid {$type} slug specified. The slug cannot be '.' or '..'." );
833834
}
835+
if ( ! preg_match( '/^[a-zA-Z0-9_-]+$/', $slug ) ) {
836+
WP_CLI::error( "Invalid {$type} slug specified. The slug can only contain alphanumeric characters, underscores, and dashes." );
837+
}
834838
if ( 'theme' === $type ) {
835839
$theme = wp_get_theme( $slug );
836840
if ( $theme->exists() ) {
@@ -858,6 +862,13 @@ private function scaffold_plugin_theme_tests( $args, $assoc_args, $type ) {
858862
}
859863
if ( empty( $slug ) ) {
860864
$slug = Utils\basename( $target_dir );
865+
// Validate derived slug as well.
866+
if ( in_array( $slug, [ '.', '..' ], true ) ) {
867+
WP_CLI::error( "Invalid {$type} slug specified. The slug cannot be '.' or '..'." );
868+
}
869+
if ( ! preg_match( '/^[a-zA-Z0-9_-]+$/', $slug ) ) {
870+
WP_CLI::error( "Invalid {$type} slug specified. The slug can only contain alphanumeric characters, underscores, and dashes." );
871+
}
861872
}
862873
}
863874

@@ -1200,7 +1211,7 @@ private static function canonicalize_path( $path ) {
12001211
/**
12011212
* Gets an active theme's name when true provided or the same name otherwise.
12021213
*
1203-
* @param string|bool $theme Theme name or true.
1214+
* @param string|true $theme Theme name or true.
12041215
* @return string
12051216
*/
12061217
private function get_theme_name( $theme ) {

0 commit comments

Comments
 (0)