From: Brad Jorsch Date: Tue, 22 May 2018 21:12:30 +0000 (-0400) Subject: IP: Fix sanitization of IPv4 ranges X-Git-Tag: 1.34.0-rc.0~5320^2 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=57445f04259077c5bf927fc6a6dca189fbe86214 IP: Fix sanitization of IPv4 ranges '000.000.000.000/24' should sanitize to '0.0.0.0/24', not '0.0.0.000/24'. Change-Id: I9364cb268dcc9b9b24aa1c627a87482978c4cf34 --- diff --git a/includes/libs/IP.php b/includes/libs/IP.php index f95bb1ebde..06589d2787 100644 --- a/includes/libs/IP.php +++ b/includes/libs/IP.php @@ -164,7 +164,7 @@ class IP { } if ( self::isIPv4( $ip ) ) { // Remove leading 0's from octet representation of IPv4 address - $ip = preg_replace( '/(?:^|(?<=\.))0+(?=[1-9]|0\.|0$)/', '', $ip ); + $ip = preg_replace( '!(?:^|(?<=\.))0+(?=[1-9]|0[./]|0$)!', '', $ip ); return $ip; } // Remove any whitespaces, convert to upper case diff --git a/tests/phpunit/includes/libs/IPTest.php b/tests/phpunit/includes/libs/IPTest.php index 9702c82c60..9ec53c00c7 100644 --- a/tests/phpunit/includes/libs/IPTest.php +++ b/tests/phpunit/includes/libs/IPTest.php @@ -325,6 +325,7 @@ class IPTest extends PHPUnit\Framework\TestCase { [ '0.0.0.0', '0.0.0.0' ], [ '0.0.0.0', '00.00.00.00' ], [ '0.0.0.0', '000.000.000.000' ], + [ '0.0.0.0/24', '000.000.000.000/24' ], [ '141.0.11.253', '141.000.011.253' ], [ '1.2.4.5', '1.2.4.5' ], [ '1.2.4.5', '01.02.04.05' ],