Skip to content

Commit ca25b73

Browse files
authored
Merge pull request #164 from Ancocodet/fail-on-empty-table-prefix
2 parents d4d505f + 88dfd8b commit ca25b73

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

features/config-create.feature

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,31 @@ Feature: Create a wp-config file
119119
define( 'AUTH_SALT',
120120
"""
121121
122+
Scenario: Configure with invalid table prefix
123+
Given an empty directory
124+
And WP files
125+
126+
When I try `wp config create --skip-check --dbname=somedb --dbuser=someuser --dbpass=sompassword --dbprefix=""`
127+
Then the return code should be 1
128+
And STDERR should contain:
129+
"""
130+
Error: --dbprefix cannot be empty
131+
"""
132+
133+
When I try `wp config create --skip-check --dbname=somedb --dbuser=someuser --dbpass=sompassword --dbprefix=" "`
134+
Then the return code should be 1
135+
And STDERR should contain:
136+
"""
137+
Error: --dbprefix can only contain numbers, letters, and underscores.
138+
"""
139+
140+
When I try `wp config create --skip-check --dbname=somedb --dbuser=someuser --dbpass=sompassword --dbprefix="wp-"`
141+
Then the return code should be 1
142+
And STDERR should contain:
143+
"""
144+
Error: --dbprefix can only contain numbers, letters, and underscores.
145+
"""
146+
122147
@require-php-7.0
123148
Scenario: Configure with salts generated
124149
Given an empty directory

src/Config_Command.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ public function create( $_, $assoc_args ) {
149149
'config-file' => rtrim( ABSPATH, '/\\' ) . '/wp-config.php',
150150
];
151151
$assoc_args = array_merge( $defaults, $assoc_args );
152+
if ( empty( $assoc_args['dbprefix'] ) ) {
153+
WP_CLI::error( '--dbprefix cannot be empty' );
154+
}
152155
if ( preg_match( '|[^a-z0-9_]|i', $assoc_args['dbprefix'] ) ) {
153156
WP_CLI::error( '--dbprefix can only contain numbers, letters, and underscores.' );
154157
}

0 commit comments

Comments
 (0)