@@ -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