From b33967cd31296216bd000c6498e388ecc9658802 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Fri, 24 Nov 2017 05:52:46 +0000 Subject: [PATCH] WPDB: Fix the parsing of sockets which contain colons within the socket name (used on some cloud providers). Props natacado. Fixes #42634 for trunk. Built from https://develop.svn.wordpress.org/trunk@42226 git-svn-id: http://core.svn.wordpress.org/trunk@42055 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/version.php | 2 +- wp-includes/wp-db.php | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/wp-includes/version.php b/wp-includes/version.php index 16bc5121b1..2b6d02492f 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '5.0-alpha-42225'; +$wp_version = '5.0-alpha-42226'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. diff --git a/wp-includes/wp-db.php b/wp-includes/wp-db.php index 19f79c42b0..d37e51370e 100644 --- a/wp-includes/wp-db.php +++ b/wp-includes/wp-db.php @@ -1643,14 +1643,21 @@ class wpdb { $socket = null; $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. // An IPv6 address will always contain at least two colons. if ( substr_count( $host, ':' ) > 1 ) { - $pattern = '#^(?:\[)?(?[0-9a-fA-F:]+)(?:\]:(?[\d]+))?(?:/(?.+))?#'; + $pattern = '#^(?:\[)?(?[0-9a-fA-F:]+)(?:\]:(?[\d]+))?#'; $is_ipv6 = true; } else { // We seem to be dealing with an IPv4 address. - $pattern = '#^(?[^:/]*)(?::(?[\d]+))?(?::(?.+))?#'; + $pattern = '#^(?[^:/]*)(?::(?[\d]+))?#'; } $matches = array(); @@ -1662,7 +1669,7 @@ class wpdb { } $host = ''; - foreach ( array( 'host', 'port', 'socket' ) as $component ) { + foreach ( array( 'host', 'port' ) as $component ) { if ( ! empty( $matches[ $component ] ) ) { $$component = $matches[ $component ]; }