@@ -553,15 +553,25 @@ MYSQLND_METHOD(mysqlnd_conn_data, get_scheme)(MYSQLND_CONN_DATA * conn, MYSQLND_
553553 port = 3306 ;
554554 }
555555
556- /* ipv6 addresses are in the format [address]:port */
557556 if (hostname .s [0 ] != '[' && mysqlnd_fast_is_ipv6_address (hostname .s )) {
557+ /* IPv6 without square brackets so without port */
558558 transport .l = mnd_sprintf (& transport .s , 0 , "tcp://[%s]:%u" , hostname .s , port );
559559 } else {
560+ char * p ;
561+
562+ /* IPv6 addresses are in the format [address]:port */
563+ if (hostname .s [0 ] == '[' ) { /* IPv6 */
564+ p = strchr (hostname .s , ']' );
565+ if (p && p [1 ] != ':' ) {
566+ p = NULL ;
567+ }
568+ } else { /* IPv4 or name */
569+ p = strchr (hostname .s , ':' );
570+ }
560571 /* Could already contain a port number, in which case we should not add an extra port.
561572 * See GH-8978. In a port doubling scenario, the first port would be used so we do the same to keep BC. */
562- if (strchr ( hostname . s , ':' ) && ! mysqlnd_fast_is_ipv6_address ( hostname . s ) ) {
573+ if (p ) {
563574 /* TODO: Ideally we should be able to get rid of this workaround in the future. */
564- /* TODO: IPv6 address enclosed in square brackets is not handled, ex [::1]:3306 */
565575 transport .l = mnd_sprintf (& transport .s , 0 , "tcp://%s" , hostname .s );
566576 } else {
567577 transport .l = mnd_sprintf (& transport .s , 0 , "tcp://%s:%u" , hostname .s , port );
0 commit comments