Index: branches/REL1_18/phase3/tests/phpunit/includes/IPTest.php |
— | — | @@ -482,4 +482,27 @@ |
483 | 483 | ); |
484 | 484 | } |
485 | 485 | |
| 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:c1:A2:3:4:5:c6:7', '0:C1:A2:3:4:5:C6:7', 'IPv6 non range' ), |
| 507 | + ); |
| 508 | + } |
486 | 509 | } |
Property changes on: branches/REL1_18/phase3/includes/resourceloader/ResourceLoader.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
487 | 510 | Merged /trunk/phase3/includes/resourceloader/ResourceLoader.php:r98602-98603,98605 |
Index: branches/REL1_18/phase3/includes/IP.php |
— | — | @@ -691,10 +691,13 @@ |
692 | 692 | * @param $range String: IP address to normalize |
693 | 693 | * @return string |
694 | 694 | */ |
695 | | - public static function sanitizeRange( $range ){ |
| 695 | + public static function sanitizeRange( $range ) { |
696 | 696 | list( /*...*/, $bits ) = self::parseCIDR( $range ); |
697 | 697 | list( $start, /*...*/ ) = self::parseRange( $range ); |
698 | 698 | $start = self::formatHex( $start ); |
| 699 | + if ( $bits === false ) { |
| 700 | + return $start; // wasn't actually a range |
| 701 | + } |
699 | 702 | return "$start/$bits"; |
700 | 703 | } |
701 | 704 | } |
Property changes on: branches/REL1_18/phase3/includes |
___________________________________________________________________ |
Modified: svn:mergeinfo |
702 | 705 | Merged /trunk/phase3/includes:r98602-98603,98605 |
Property changes on: branches/REL1_18/phase3 |
___________________________________________________________________ |
Modified: svn:mergeinfo |
703 | 706 | Merged /trunk/phase3:r98602-98603,98605 |