Skip to content

Commit a265c7d

Browse files
Copilotswissspidy
andcommitted
Fix empty character set parameter issue in mysqlcheck commands
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent b0f6bcc commit a265c7d

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

features/db-check.feature

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,29 @@ Feature: Check the database
136136
When I try `wp db check --no-defaults --debug`
137137
Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysqlcheck|mariadb-check) --no-defaults %s#
138138

139+
Scenario: Empty DB credentials should not cause empty parameter errors
140+
Given a WP install
141+
And a wp-config.php file:
142+
"""
143+
<?php
144+
define( 'DB_NAME', 'wp_cli_test' );
145+
define( 'DB_USER', 'wp_cli_test' );
146+
define( 'DB_PASSWORD', 'password1' );
147+
define( 'DB_HOST', 'localhost' );
148+
define( 'DB_CHARSET', '' );
149+
define( 'DB_COLLATE', '' );
150+
$table_prefix = 'wp_';
151+
require_once ABSPATH . 'wp-settings.php';
152+
"""
153+
154+
When I run `wp db check --debug`
155+
Then STDERR should not contain:
156+
"""
157+
--default-character-set=
158+
"""
159+
And the return code should be 0
160+
And STDOUT should contain:
161+
"""
162+
Success: Database checked.
163+
"""
164+

src/DB_Command.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,6 +1827,15 @@ private static function run( $cmd, $assoc_args = [], $send_to_shell = true, $int
18271827
unset( $assoc_args['dbpass'], $assoc_args['password'] );
18281828
}
18291829

1830+
// Filter out empty string values to avoid passing empty parameters to MySQL commands
1831+
// which can cause errors like "Character set '' is not a compiled character set"
1832+
$required = array_filter(
1833+
$required,
1834+
static function ( $value ) {
1835+
return '' !== $value;
1836+
}
1837+
);
1838+
18301839
$final_args = array_merge( $required, $assoc_args );
18311840

18321841
// Adapt ordering of arguments.

0 commit comments

Comments
 (0)