-
Notifications
You must be signed in to change notification settings - Fork 67
Filter empty database parameters to prevent MySQL command failures #308
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 ); | ||
|
Comment on lines
+1830
to
1839
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current implementation filters empty values from the
To ensure all empty parameters are correctly filtered, regardless of their origin, the filtering should be applied to the $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;
}
); |
||
|
|
||
| // Adapt ordering of arguments. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test scenario is a great addition for verifying the behavior with empty credentials. However, it specifically tests an empty
DB_CHARSET, which is already handled by existing logic inDB_Command::run()(&& constant( 'DB_CHARSET' )) and doesn't actually exercise the newarray_filterlogic.To create a more effective test that validates the new filtering mechanism, consider testing a scenario where
DB_HOSTorDB_USERis an empty string. This would directly test whether thearray_filtercorrectly removes the empty parameter before it's passed to the MySQL command.For example, you could add a scenario like this: