From fd247bc2e4e7ef2b6239655e11c0464f15e6ab3d Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Wed, 11 Oct 2017 00:10:47 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@41820 git-svn-id: http://core.svn.wordpress.org/trunk@41654 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/version.php | 2 +- wp-includes/wp-db.php | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/wp-includes/version.php b/wp-includes/version.php index 1a834af003..1980a5f570 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.9-beta1-41819'; +$wp_version = '4.9-beta1-41820'; /** * 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 9759438a0c..a5903b4187 100644 --- a/wp-includes/wp-db.php +++ b/wp-includes/wp-db.php @@ -1479,7 +1479,7 @@ class wpdb { $port = null; $socket = null; $is_ipv6 = false; - + if ( $host_data = $this->parse_db_host( $this->dbhost ) ) { list( $host, $port, $socket, $is_ipv6 ) = $host_data; } @@ -1621,9 +1621,10 @@ class wpdb { return false; } + $host = ''; foreach ( array( 'host', 'port', 'socket' ) as $component ) { - if ( array_key_exists( $component, $matches ) ) { - $$component = $matches[$component]; + if ( ! empty( $matches[ $component ] ) ) { + $$component = $matches[ $component ]; } }