Skip to content
Open
Show file tree
Hide file tree
Changes from 9 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
28 changes: 28 additions & 0 deletions features/db-check.feature
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,31 @@ 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', '' );
define( 'DB_CHARSET', 'utf8' );
$table_prefix = 'wp_';
require_once ABSPATH . 'wp-settings.php';
"""

When I try `wp db check --debug`
Then STDERR should contain:
Comment thread
swissspidy marked this conversation as resolved.
"""
Debug (db): Final MySQL command:
"""
And STDERR should not contain:
"""
--host=''
"""
And STDERR should not contain:
"""
--host=
"""
Comment thread
swissspidy marked this conversation as resolved.

Comment thread
swissspidy marked this conversation as resolved.
9 changes: 9 additions & 0 deletions src/DB_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -1853,6 +1853,15 @@ private static function run( $cmd, $assoc_args = [], $send_to_shell = true, $int

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

// 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"
$final_args = array_filter(
$final_args,
static function ( $value ) {
return null !== $value && '' !== $value;
}
Comment thread
swissspidy marked this conversation as resolved.
Outdated
);

// Adapt ordering of arguments.
uksort(
$final_args,
Expand Down
Loading