[wp-trac] [WordPress Trac] #41083: IP with port number triggers warnings in WP_Community_Events

WordPress Trac noreply at wordpress.org
Tue Sep 5 18:39:39 UTC 2017


#41083: IP with port number triggers warnings in WP_Community_Events
--------------------------------------+-----------------------------
 Reporter:  EatonZ                    |       Owner:  iandunn
     Type:  defect (bug)              |      Status:  assigned
 Priority:  normal                    |   Milestone:  4.9
Component:  Administration            |     Version:  4.8
 Severity:  normal                    |  Resolution:
 Keywords:  good-first-bug has-patch  |     Focuses:  administration
--------------------------------------+-----------------------------

Comment (by birgire):

 Here's a modified regex from the patch by @schlessera in ticket #41722

 I changed it to preg_replace and removed the port match.

 The regex might not be the way forward here, but a stripped down helper
 function might look like:

 {{{
 function strip_ip_address_port( $address ) {
     if ( substr_count( $address, ':' ) > 1 ) {                      //
 IPv6
         $pattern = '#^(?:\[)?([0-9a-fA-F:]+)(?:\]:([\d]+))?#';
     } elseif( 3 === substr_count( $address, '.' ) ) {                //
 IPv4
         $pattern = '#^(?:\[)?([^:]+)(?::([\d]+))?#';
     } else {                                                         //
 Not valid
         return false;
     }
     return preg_replace( $pattern, '\1', $address );
 }
 }}}

 or if I understand the patch by @iandunn correctly, we could try to adjust
 it to (untested):

 {{{
 protected static function strip_ip_address_port( $ip_address,
 $address_format ) {
         if ( 4 === $address_format ) {
                 $port_delimiter = strpos( $ip_address, ':' );

                 if ( $port_delimiter ) {
                         $ip_address = substr( $ip_address, 0,
 $port_delimiter );
                 }
         } elseif ( 6 === $address_format ) {
                 $pattern = '#^(?:\[)?([0-9a-fA-F:]+)(?:\]:([\d]+))?#';
                 $ip_address = preg_replace( $pattern, '\1', $ip_address );
         }
         return $ip_address;
 }

 }}}

 but I would have to look further into that.

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


More information about the wp-trac mailing list