Database: When parsing the host, leave the port and socket as null
if they're not defined.
This fixes a change in behaviour introduced by [41629]. The host is set to an empty string when it isn't defined, this continues existing behaviour. In particular, the mysqli library treats a `null` host as being the same as `localhost`, which is not always the intended behaviour. Props birgire, markjaquith, pento. Fixes #41722. git-svn-id: https://develop.svn.wordpress.org/trunk@41820 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
32e7a51a01
commit
0e5b75b8be
@ -1621,8 +1621,9 @@ class wpdb {
|
||||
return false;
|
||||
}
|
||||
|
||||
$host = '';
|
||||
foreach ( array( 'host', 'port', 'socket' ) as $component ) {
|
||||
if ( array_key_exists( $component, $matches ) ) {
|
||||
if ( ! empty( $matches[ $component ] ) ) {
|
||||
$$component = $matches[ $component ];
|
||||
}
|
||||
}
|
||||
|
@ -1208,10 +1208,10 @@ class Tests_DB extends WP_UnitTestCase {
|
||||
|
||||
list( $parsed_host, $parsed_port, $parsed_socket, $parsed_is_ipv6 ) = $data;
|
||||
|
||||
$this->assertEquals( $host, $parsed_host );
|
||||
$this->assertEquals( $port, $parsed_port );
|
||||
$this->assertEquals( $socket, $parsed_socket );
|
||||
$this->assertEquals( $is_ipv6, $parsed_is_ipv6 );
|
||||
$this->assertSame( $host, $parsed_host );
|
||||
$this->assertSame( $port, $parsed_port );
|
||||
$this->assertSame( $socket, $parsed_socket );
|
||||
$this->assertSame( $is_ipv6, $parsed_is_ipv6 );
|
||||
}
|
||||
}
|
||||
|
||||
@ -1220,7 +1220,7 @@ class Tests_DB extends WP_UnitTestCase {
|
||||
array(
|
||||
'', // DB_HOST
|
||||
false, // Expect parse_db_host to bail for this hostname
|
||||
null, // Parsed host
|
||||
'', // Parsed host
|
||||
null, // Parsed port
|
||||
null, // Parsed socket
|
||||
false, // is_ipv6
|
||||
@ -1228,7 +1228,7 @@ class Tests_DB extends WP_UnitTestCase {
|
||||
array(
|
||||
':3306',
|
||||
false,
|
||||
null,
|
||||
'',
|
||||
'3306',
|
||||
null,
|
||||
false,
|
||||
@ -1236,7 +1236,7 @@ class Tests_DB extends WP_UnitTestCase {
|
||||
array(
|
||||
':/tmp/mysql.sock',
|
||||
false,
|
||||
null,
|
||||
'',
|
||||
null,
|
||||
'/tmp/mysql.sock',
|
||||
false,
|
||||
|
Loading…
Reference in New Issue
Block a user