Skip to content
Draft
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
34 changes: 34 additions & 0 deletions features/db-check.feature
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,37 @@ Feature: Check the database
When I try `wp db check --no-defaults --debug`
Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysqlcheck|mariadb-check) --no-defaults %s#

Scenario: Empty DB credentials should not cause empty parameter errors
Given a WP install
And a wp-config.php file:
"""
<?php
define( 'DB_NAME', 'wp_cli_test' );
define( 'DB_USER', 'wp_cli_test' );
define( 'DB_PASSWORD', 'password1' );
define( 'DB_HOST', 'localhost' );
define( 'DB_CHARSET', '' );
define( 'DB_COLLATE', '' );
$table_prefix = 'wp_';
require_once ABSPATH . 'wp-settings.php';
"""

When I run `wp db check --debug`
Then STDERR should contain:
"""
Debug (db): Final MySQL command:
"""
And STDERR should not contain:
"""
--default-character-set=''
"""
And STDERR should not contain:
"""
--default-character-set=
"""
And the return code should be 0
And STDOUT should contain:
"""
Success: Database checked.
"""

9 changes: 9 additions & 0 deletions src/DB_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -1827,6 +1827,15 @@ private static function run( $cmd, $assoc_args = [], $send_to_shell = true, $int
unset( $assoc_args['dbpass'], $assoc_args['password'] );
}

// Filter out empty string values to avoid passing empty parameters to MySQL commands
// which can cause errors like "Character set '' is not a compiled character set"
$required = array_filter(
$required,
static function ( $value ) {
return null !== $value && '' !== $value;
}
);

$final_args = array_merge( $required, $assoc_args );

// Adapt ordering of arguments.
Expand Down
Loading