diff --git a/features/config-create.feature b/features/config-create.feature index 18aeada5..9d52ce23 100644 --- a/features/config-create.feature +++ b/features/config-create.feature @@ -119,6 +119,31 @@ Feature: Create a wp-config file define( 'AUTH_SALT', """ + Scenario: Configure with invalid table prefix + Given an empty directory + And WP files + + When I try `wp config create --skip-check --dbname=somedb --dbuser=someuser --dbpass=sompassword --dbprefix=""` + Then the return code should be 1 + And STDERR should contain: + """ + Error: --dbprefix cannot be empty + """ + + When I try `wp config create --skip-check --dbname=somedb --dbuser=someuser --dbpass=sompassword --dbprefix=" "` + Then the return code should be 1 + And STDERR should contain: + """ + Error: --dbprefix can only contain numbers, letters, and underscores. + """ + + When I try `wp config create --skip-check --dbname=somedb --dbuser=someuser --dbpass=sompassword --dbprefix="wp-"` + Then the return code should be 1 + And STDERR should contain: + """ + Error: --dbprefix can only contain numbers, letters, and underscores. + """ + @require-php-7.0 Scenario: Configure with salts generated Given an empty directory diff --git a/src/Config_Command.php b/src/Config_Command.php index 95a486ed..4b38bfa4 100644 --- a/src/Config_Command.php +++ b/src/Config_Command.php @@ -149,6 +149,9 @@ public function create( $_, $assoc_args ) { 'config-file' => rtrim( ABSPATH, '/\\' ) . '/wp-config.php', ]; $assoc_args = array_merge( $defaults, $assoc_args ); + if ( empty( $assoc_args['dbprefix'] ) ) { + WP_CLI::error( '--dbprefix cannot be empty' ); + } if ( preg_match( '|[^a-z0-9_]|i', $assoc_args['dbprefix'] ) ) { WP_CLI::error( '--dbprefix can only contain numbers, letters, and underscores.' ); }