Ticket #41083: 41083.8.diff
File 41083.8.diff, 3.4 KB (added by , 7 years ago) |
---|
-
src/wp-admin/includes/class-wp-community-events.php
diff --git src/wp-admin/includes/class-wp-community-events.php src/wp-admin/includes/class-wp-community-events.php index 410f9b6237..05fbac46ea 100644
class WP_Community_Events { 279 279 280 280 if ( $is_ipv6 ) { 281 281 // IPv6 addresses will always be enclosed in [] if there's a port. 282 $ ip_start = 1;283 $ ip_end = (int) strpos( $client_ip, ']' ) - 1;282 $left_bracket = strpos( $client_ip, '[' ); 283 $right_bracket = strpos( $client_ip, ']' ); 284 284 $netmask = 'ffff:ffff:ffff:ffff:0000:0000:0000:0000'; 285 285 286 286 // Strip the port (and [] from IPv6 addresses), if they exist. 287 if ( $ip_end > 0 ) { 288 $client_ip = substr( $client_ip, $ip_start, $ip_end ); 289 } 287 if ( false !== $left_bracket && false !== $right_bracket ) { 288 $client_ip = substr( $client_ip, $left_bracket + 1, $right_bracket - $left_bracket - 1 ); 289 } elseif ( false !== $left_bracket || false !== $right_bracket ) { 290 // The IP has one bracket, but not both, so it's malformed. 291 return false; 292 } // elseif it has any invalid chars (not digit, colon, bracket, letter, %, maybe others) 293 // then return false? 290 294 291 295 // Partially anonymize the IP by reducing it to the corresponding network ID. 292 296 if ( function_exists( 'inet_pton' ) && function_exists( 'inet_ntop' ) ) { -
tests/phpunit/tests/admin/includesCommunityEvents.php
diff --git tests/phpunit/tests/admin/includesCommunityEvents.php tests/phpunit/tests/admin/includesCommunityEvents.php index e2f8528c85..b2369e48db 100644
class Test_WP_Community_Events extends WP_UnitTestCase { 284 284 'unknown', 285 285 false, 286 286 ), 287 // Invalid IP. Sometimes proxies add things like this, or other arbitrary strings. 288 array( 289 'or=\"[1000:0000:0000:0000:0000:0000:0000:0001', 290 false, 291 ), 292 // Invalid IP. Sometimes proxies add things like this, or other arbitrary strings. 293 array( 294 'or=\"1000:0000:0000:0000:0000:0000:0000:0001', 295 false, 296 ), 297 // Invalid IP. Sometimes proxies add things like this, or other arbitrary strings. 298 array( 299 '1000:0000:0000:0000:0000:0000:0000:0001or=\"', 300 false, 301 ), 302 // Malformed string with valid IP substring. Sometimes proxies add things like this, or other arbitrary strings. 303 array( 304 'or=\"[1000:0000:0000:0000:0000:0000:0000:0001]:400', 305 '1000::', 306 ), 307 // Malformed string with valid IP substring. Sometimes proxies add things like this, or other arbitrary strings. 308 array( 309 'or=\"[1000:0000:0000:0000:0000:0000:0000:0001]', 310 '1000::', 311 ), 312 // Malformed string with valid IP substring. Sometimes proxies add things like this, or other arbitrary strings. 313 array( 314 'or=\"[1000:0000:0000:0000:0000:0000:0000:0001]400', 315 '1000::', 316 ), 317 // Malformed string with valid IP substring. Sometimes proxies add things like this, or other arbitrary strings. 318 array( 319 '[1000:0000:0000:0000:0000:0000:0000:0001]:235\"or=', 320 '1000::', 321 ), 287 322 // IPv4, no port 288 323 array( 289 324 '10.20.30.45', … … class Test_WP_Community_Events extends WP_UnitTestCase { 364 399 '[::127.0.0.1]:30000', 365 400 '::ffff:127.0.0.0', 366 401 ), 402 // IPv6 with reachability scope 403 array( 404 'fe80::b059:65f4:e877:c40%16', 405 'fe80::' 406 ), 407 // IPv6 with reachability scope 408 array( 409 'fe80::b059:65f4:e877:c40%eth0', 410 'fe80::' 411 ), 367 412 ); 368 413 } 369 414 }