[wp-trac] [WordPress Trac] #41722: wpdb::db_connect() does not connect to IPv6 address of mysql server

WordPress Trac noreply at wordpress.org
Mon Aug 28 15:08:00 UTC 2017


#41722: wpdb::db_connect() does not connect to IPv6 address of mysql server
-------------------------------------+--------------------
 Reporter:  fierevere                |       Owner:
     Type:  defect (bug)             |      Status:  new
 Priority:  normal                   |   Milestone:  4.9
Component:  Database                 |     Version:  4.8.1
 Severity:  normal                   |  Resolution:
 Keywords:  has-patch needs-testing  |     Focuses:
-------------------------------------+--------------------

Comment (by birgire):

 Here's a first draft for db host strings examples:

 {{{

 // db hosts and the expected host, port, socket
 $data = array(
         // db_host                              // host
 //port          //socket
         '::1'                           => array( '[::1]',
 null,           null                    ),
         '[::1]'                         => array( '[::1]',
 null,           null                    ),
         '[::1]:3306'                    => array( '[::1]',
 '3306',         null                    ),
         '127.0.0.1'                     => array( '127.0.0.1',
 null,           null                    ),
         '127.0.0.1:3306'                => array( '127.0.0.1',
 '3306',         null                    ),
         'example.com'                   => array( 'example.com',
 null,           null                    ),
         'example.com:3306'              => array( 'example.com',
 '3306',         null                    ),
         'localhost'                     => array( 'localhost',
 null,           null                    ),
         'localhost:/tmp/mysql.sock'     => array( 'localhost',
 null,           '/tmp/mysql.sock'       ),
 );
 }}}

 Here we assume the mysql native driver.

 If we run it through:

 {{{
 foreach( (array) $data as $db_host => $expected ) {
         $result = $wpdb->parse_db_host( $db_host );
         $this->assertEqualSets( $expected, $result );
 }

 }}}

 we get:

 {{{
 FAILURES!
 Tests: 1, Assertions: 9, Failures: 1.
 }}}

 The socket test seem to fail.

 I wonder if the brackets should be handled outside of the
 {{{parse_db_host()}}} function? That way the output would be more
 predictable, as it wouldn't depend on the library. It would also make the
 above testing easier.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/41722#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list