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
@ -1479,7 +1479,7 @@ class wpdb {
|
|||||||
$port = null;
|
$port = null;
|
||||||
$socket = null;
|
$socket = null;
|
||||||
$is_ipv6 = false;
|
$is_ipv6 = false;
|
||||||
|
|
||||||
if ( $host_data = $this->parse_db_host( $this->dbhost ) ) {
|
if ( $host_data = $this->parse_db_host( $this->dbhost ) ) {
|
||||||
list( $host, $port, $socket, $is_ipv6 ) = $host_data;
|
list( $host, $port, $socket, $is_ipv6 ) = $host_data;
|
||||||
}
|
}
|
||||||
@ -1621,9 +1621,10 @@ class wpdb {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$host = '';
|
||||||
foreach ( array( 'host', 'port', 'socket' ) as $component ) {
|
foreach ( array( 'host', 'port', 'socket' ) as $component ) {
|
||||||
if ( array_key_exists( $component, $matches ) ) {
|
if ( ! empty( $matches[ $component ] ) ) {
|
||||||
$$component = $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;
|
list( $parsed_host, $parsed_port, $parsed_socket, $parsed_is_ipv6 ) = $data;
|
||||||
|
|
||||||
$this->assertEquals( $host, $parsed_host );
|
$this->assertSame( $host, $parsed_host );
|
||||||
$this->assertEquals( $port, $parsed_port );
|
$this->assertSame( $port, $parsed_port );
|
||||||
$this->assertEquals( $socket, $parsed_socket );
|
$this->assertSame( $socket, $parsed_socket );
|
||||||
$this->assertEquals( $is_ipv6, $parsed_is_ipv6 );
|
$this->assertSame( $is_ipv6, $parsed_is_ipv6 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1220,7 +1220,7 @@ class Tests_DB extends WP_UnitTestCase {
|
|||||||
array(
|
array(
|
||||||
'', // DB_HOST
|
'', // DB_HOST
|
||||||
false, // Expect parse_db_host to bail for this hostname
|
false, // Expect parse_db_host to bail for this hostname
|
||||||
null, // Parsed host
|
'', // Parsed host
|
||||||
null, // Parsed port
|
null, // Parsed port
|
||||||
null, // Parsed socket
|
null, // Parsed socket
|
||||||
false, // is_ipv6
|
false, // is_ipv6
|
||||||
@ -1228,7 +1228,7 @@ class Tests_DB extends WP_UnitTestCase {
|
|||||||
array(
|
array(
|
||||||
':3306',
|
':3306',
|
||||||
false,
|
false,
|
||||||
null,
|
'',
|
||||||
'3306',
|
'3306',
|
||||||
null,
|
null,
|
||||||
false,
|
false,
|
||||||
@ -1236,7 +1236,7 @@ class Tests_DB extends WP_UnitTestCase {
|
|||||||
array(
|
array(
|
||||||
':/tmp/mysql.sock',
|
':/tmp/mysql.sock',
|
||||||
false,
|
false,
|
||||||
null,
|
'',
|
||||||
null,
|
null,
|
||||||
'/tmp/mysql.sock',
|
'/tmp/mysql.sock',
|
||||||
false,
|
false,
|
||||||
|
Loading…
Reference in New Issue
Block a user