Skip to content

Commit f29a0cc

Browse files
Copilotswissspidy
andcommitted
Add validation to reject plugin/theme slugs ending with slashes
Co-authored-by: swissspidy <[email protected]>
1 parent bc6d673 commit f29a0cc

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

features/scaffold-plugin-tests.feature

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,20 @@ Feature: Scaffold plugin unit tests
240240
"""
241241
And the return code should be 1
242242

243+
When I try `wp scaffold plugin-tests my-plugin/`
244+
Then STDERR should be:
245+
"""
246+
Error: Invalid plugin slug specified. The slug cannot end with a slash.
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 cannot end with a slash.
254+
"""
255+
And the return code should be 1
256+
243257
Scenario: Scaffold plugin tests with invalid directory
244258
Given a WP install
245259
And I run `wp scaffold plugin hello-world --skip-tests`

features/scaffold-theme-tests.feature

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,20 @@ Feature: Scaffold theme unit tests
219219
"""
220220
And the return code should be 1
221221

222+
When I try `wp scaffold theme-tests t12child/`
223+
Then STDERR should be:
224+
"""
225+
Error: Invalid theme slug specified. The slug cannot end with a slash.
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 cannot end with a slash.
233+
"""
234+
And the return code should be 1
235+
222236
Scenario: Scaffold theme tests with invalid directory
223237
When I try `wp scaffold theme-tests twentytwelve --dir=non-existent-dir`
224238
Then STDERR should be:

src/Scaffold_Command.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,10 @@ private function scaffold_plugin_theme_tests( $args, $assoc_args, $type ) {
829829
if ( in_array( $slug, [ '.', '..' ], true ) ) {
830830
WP_CLI::error( "Invalid {$type} slug specified. The slug cannot be '.' or '..'." );
831831
}
832+
// Reject slugs ending with slashes to prevent corrupted bootstrap.php files.
833+
if ( '/' === substr( $slug, -1 ) || '\\' === substr( $slug, -1 ) ) {
834+
WP_CLI::error( "Invalid {$type} slug specified. The slug cannot end with a slash." );
835+
}
832836
if ( 'theme' === $type ) {
833837
$theme = wp_get_theme( $slug );
834838
if ( $theme->exists() ) {

0 commit comments

Comments
 (0)