WPDB: Fix the parsing of sockets which contain colons within the socket name (used on some cloud providers).
Props natacado. Fixes #42634 for trunk. git-svn-id: https://develop.svn.wordpress.org/trunk@42226 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
555eab6391
commit
b8c4faff72
@ -1643,14 +1643,21 @@ class wpdb {
|
|||||||
$socket = null;
|
$socket = null;
|
||||||
$is_ipv6 = false;
|
$is_ipv6 = false;
|
||||||
|
|
||||||
|
// First peel off the socket parameter from the right, if it exists.
|
||||||
|
$socket_pos = strpos( $host, ':/' );
|
||||||
|
if ( $socket_pos !== false ) {
|
||||||
|
$socket = substr( $host, $socket_pos + 1 );
|
||||||
|
$host = substr( $host, 0, $socket_pos );
|
||||||
|
}
|
||||||
|
|
||||||
// We need to check for an IPv6 address first.
|
// We need to check for an IPv6 address first.
|
||||||
// An IPv6 address will always contain at least two colons.
|
// An IPv6 address will always contain at least two colons.
|
||||||
if ( substr_count( $host, ':' ) > 1 ) {
|
if ( substr_count( $host, ':' ) > 1 ) {
|
||||||
$pattern = '#^(?:\[)?(?<host>[0-9a-fA-F:]+)(?:\]:(?<port>[\d]+))?(?:/(?<socket>.+))?#';
|
$pattern = '#^(?:\[)?(?<host>[0-9a-fA-F:]+)(?:\]:(?<port>[\d]+))?#';
|
||||||
$is_ipv6 = true;
|
$is_ipv6 = true;
|
||||||
} else {
|
} else {
|
||||||
// We seem to be dealing with an IPv4 address.
|
// We seem to be dealing with an IPv4 address.
|
||||||
$pattern = '#^(?<host>[^:/]*)(?::(?<port>[\d]+))?(?::(?<socket>.+))?#';
|
$pattern = '#^(?<host>[^:/]*)(?::(?<port>[\d]+))?#';
|
||||||
}
|
}
|
||||||
|
|
||||||
$matches = array();
|
$matches = array();
|
||||||
@ -1662,7 +1669,7 @@ class wpdb {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$host = '';
|
$host = '';
|
||||||
foreach ( array( 'host', 'port', 'socket' ) as $component ) {
|
foreach ( array( 'host', 'port' ) as $component ) {
|
||||||
if ( ! empty( $matches[ $component ] ) ) {
|
if ( ! empty( $matches[ $component ] ) ) {
|
||||||
$$component = $matches[ $component ];
|
$$component = $matches[ $component ];
|
||||||
}
|
}
|
||||||
|
@ -1558,6 +1558,14 @@ class Tests_DB extends WP_UnitTestCase {
|
|||||||
'/tmp/mysql.sock',
|
'/tmp/mysql.sock',
|
||||||
false,
|
false,
|
||||||
),
|
),
|
||||||
|
array(
|
||||||
|
':/tmp/mysql:with_colon.sock',
|
||||||
|
false,
|
||||||
|
'',
|
||||||
|
null,
|
||||||
|
'/tmp/mysql:with_colon.sock',
|
||||||
|
false,
|
||||||
|
),
|
||||||
array(
|
array(
|
||||||
'127.0.0.1',
|
'127.0.0.1',
|
||||||
false,
|
false,
|
||||||
@ -1574,6 +1582,14 @@ class Tests_DB extends WP_UnitTestCase {
|
|||||||
null,
|
null,
|
||||||
false,
|
false,
|
||||||
),
|
),
|
||||||
|
array(
|
||||||
|
'127.0.0.1:3306:/tmp/mysql:with_colon.sock',
|
||||||
|
false,
|
||||||
|
'127.0.0.1',
|
||||||
|
'3306',
|
||||||
|
'/tmp/mysql:with_colon.sock',
|
||||||
|
false,
|
||||||
|
),
|
||||||
array(
|
array(
|
||||||
'example.com',
|
'example.com',
|
||||||
false,
|
false,
|
||||||
@ -1606,6 +1622,14 @@ class Tests_DB extends WP_UnitTestCase {
|
|||||||
'/tmp/mysql.sock',
|
'/tmp/mysql.sock',
|
||||||
false,
|
false,
|
||||||
),
|
),
|
||||||
|
array(
|
||||||
|
'localhost:/tmp/mysql:with_colon.sock',
|
||||||
|
false,
|
||||||
|
'localhost',
|
||||||
|
null,
|
||||||
|
'/tmp/mysql:with_colon.sock',
|
||||||
|
false,
|
||||||
|
),
|
||||||
array(
|
array(
|
||||||
'0000:0000:0000:0000:0000:0000:0000:0001',
|
'0000:0000:0000:0000:0000:0000:0000:0001',
|
||||||
false,
|
false,
|
||||||
@ -1638,6 +1662,14 @@ class Tests_DB extends WP_UnitTestCase {
|
|||||||
null,
|
null,
|
||||||
true,
|
true,
|
||||||
),
|
),
|
||||||
|
array(
|
||||||
|
'[::1]:3306:/tmp/mysql:with_colon.sock',
|
||||||
|
false,
|
||||||
|
'::1',
|
||||||
|
'3306',
|
||||||
|
'/tmp/mysql:with_colon.sock',
|
||||||
|
true,
|
||||||
|
),
|
||||||
array(
|
array(
|
||||||
'2001:0db8:0000:0000:0000:ff00:0042:8329',
|
'2001:0db8:0000:0000:0000:ff00:0042:8329',
|
||||||
false,
|
false,
|
||||||
|
Loading…
Reference in New Issue
Block a user