r98604 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98603‎ | r98604 | r98605 >
Date:05:06, 1 October 2011
Author:aaron
Status:ok
Tags:
Comment:
Modified paths:
  • /branches/wmf/1.18wmf1/includes/IP.php (modified) (history)
  • /branches/wmf/1.18wmf1/tests/phpunit/includes/IPTest.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.18wmf1/tests/phpunit/includes/IPTest.php
@@ -482,4 +482,27 @@
483483 );
484484 }
485485
 486+ /**
 487+ * Test for IP::sanitizeRange()
 488+ * @dataProvider provideIPCIDRs
 489+ */
 490+ function testSanitizeRange( $input, $expected, $description ) {
 491+ $this->assertEquals( $expected, IP::sanitizeRange( $input ), $description );
 492+ }
 493+
 494+ /**
 495+ * Provider for IP::testSanitizeRange()
 496+ */
 497+ function provideIPCIDRs() {
 498+ return array(
 499+ array( '35.56.31.252/16', '35.56.0.0/16', 'IPv4 range' ),
 500+ array( '135.16.21.252/24', '135.16.21.0/24', 'IPv4 range' ),
 501+ array( '5.36.71.252/32', '5.36.71.252/32', 'IPv4 silly range' ),
 502+ array( '5.36.71.252', '5.36.71.252', 'IPv4 non-range' ),
 503+ array( '0:1:2:3:4:c5:f6:7/96', '0:1:2:3:4:C5:0:0/96', 'IPv6 range' ),
 504+ array( '0:1:2:3:4:5:6:7/120', '0:1:2:3:4:5:6:0/120', 'IPv6 range' ),
 505+ array( '0:e1:2:3:4:5:e6:7/128', '0:E1:2:3:4:5:E6:7/128', 'IPv6 silly range' ),
 506+ array( '0:1:A2:3:4:5:c6:7', '0:1:A2:3:4:5:c6:7', 'IPv6 non range' ),
 507+ );
 508+ }
486509 }
Index: branches/wmf/1.18wmf1/includes/IP.php
@@ -691,8 +691,11 @@
692692 * @param $range String: IP address to normalize
693693 * @return string
694694 */
695 - public static function sanitizeRange( $range ){
 695+ public static function sanitizeRange( $range ) {
696696 list( /*...*/, $bits ) = self::parseCIDR( $range );
 697+ if ( $bits === false ) {
 698+ return $range; // wasn't actually a range
 699+ }
697700 list( $start, /*...*/ ) = self::parseRange( $range );
698701 $start = self::formatHex( $start );
699702 return "$start/$bits";

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r98602Made provideIPCIDRs() not add a '/' if there is no prefix length. Fixes bug 3...aaron04:54, 1 October 2011
r98603Reverted stuff from r98602 committed by mistakeaaron05:03, 1 October 2011

Status & tagging log