WordPress.org

Make WordPress Core

Changeset 41820


Ignore:
Timestamp:
10/11/2017 12:09:47 AM (23 months ago)
Author:
pento
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/wp-db.php

    r41789 r41820  
    14801480            $socket  = null;
    14811481            $is_ipv6 = false;
    1482            
     1482
    14831483            if ( $host_data = $this->parse_db_host( $this->dbhost ) ) {
    14841484                list( $host, $port, $socket, $is_ipv6 ) = $host_data;
     
    16221622        }
    16231623
     1624        $host = '';
    16241625        foreach ( array( 'host', 'port', 'socket' ) as $component ) {
    1625             if ( array_key_exists( $component, $matches ) ) {
    1626                 $$component = $matches[$component];
     1626            if ( ! empty( $matches[ $component ] ) ) {
     1627                $$component = $matches[ $component ];
    16271628            }
    16281629        }
  • trunk/tests/phpunit/tests/db.php

    r41662 r41820  
    12091209            list( $parsed_host, $parsed_port, $parsed_socket, $parsed_is_ipv6 ) = $data;
    12101210
    1211             $this->assertEquals( $host, $parsed_host );
    1212             $this->assertEquals( $port, $parsed_port );
    1213             $this->assertEquals( $socket, $parsed_socket );
    1214             $this->assertEquals( $is_ipv6, $parsed_is_ipv6 );
     1211            $this->assertSame( $host, $parsed_host );
     1212            $this->assertSame( $port, $parsed_port );
     1213            $this->assertSame( $socket, $parsed_socket );
     1214            $this->assertSame( $is_ipv6, $parsed_is_ipv6 );
    12151215        }
    12161216    }
     
    12211221                '',    // DB_HOST
    12221222                false, // Expect parse_db_host to bail for this hostname
    1223                 null,  // Parsed host
     1223                '',    // Parsed host
    12241224                null,  // Parsed port
    12251225                null,  // Parsed socket
     
    12291229                ':3306',
    12301230                false,
    1231                 null,
     1231                '',
    12321232                '3306',
    12331233                null,
     
    12371237                ':/tmp/mysql.sock',
    12381238                false,
    1239                 null,
     1239                '',
    12401240                null,
    12411241                '/tmp/mysql.sock',
Note: See TracChangeset for help on using the changeset viewer.