Merge "IP: Fix sanitization of IPv4 ranges"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 24 May 2018 00:31:31 +0000 (00:31 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 24 May 2018 00:31:31 +0000 (00:31 +0000)
includes/libs/IP.php
tests/phpunit/includes/libs/IPTest.php

index f95bb1e..06589d2 100644 (file)
@@ -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
index 9702c82..9ec53c0 100644 (file)
@@ -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' ],