Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail on empty table prefix #164

Merged
merged 4 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions features/config-create.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/Config_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.' );
}
Expand Down