From: jenkins-bot Date: Wed, 8 May 2019 19:34:29 +0000 (+0000) Subject: Merge "Fix Block::newLoad for IPv6 range blocks - follow-up to Ie8bebd8" X-Git-Tag: 1.34.0-rc.0~1758 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=9509a5a002dc80e975f7562e2518d7343f8373b5;hp=9792a09c306a6604a127a3a06f7b10cbc7e7a23f;p=lhc%2Fweb%2Fwiklou.git Merge "Fix Block::newLoad for IPv6 range blocks - follow-up to Ie8bebd8" --- diff --git a/includes/Block.php b/includes/Block.php index 472c36ed19..5b0d25611e 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -322,13 +322,13 @@ class Block extends AbstractBlock { if ( $block->getType() == self::TYPE_RANGE ) { # This is the number of bits that are allowed to vary in the block, give # or take some floating point errors - $prefix = 'v6-'; - $end = Wikimedia\base_convert( ltrim( $block->getRangeEnd(), $prefix ), 16, 10 ); - $start = Wikimedia\base_convert( ltrim( $block->getRangeStart(), $prefix ), 16, 10 ); - $size = log( $end - $start + 1, 2 ); + $target = $block->getTarget(); + $max = IP::isIPv6( $target ) ? 128 : 32; + list( $network, $bits ) = IP::parseCIDR( $target ); + $size = $max - $bits; # Rank a range block covering a single IP equally with a single-IP block - $score = self::TYPE_RANGE - 1 + ( $size / 128 ); + $score = self::TYPE_RANGE - 1 + ( $size / $max ); } else { $score = $block->getType(); diff --git a/tests/phpunit/includes/BlockTest.php b/tests/phpunit/includes/BlockTest.php index dac3b87732..3dc5e78433 100644 --- a/tests/phpunit/includes/BlockTest.php +++ b/tests/phpunit/includes/BlockTest.php @@ -175,21 +175,31 @@ class BlockTest extends MediaWikiLangTestCase { '0.0.0.0', '0.0.0.0' ], - 'Blocks to wide IPv6 range and IP' => [ - [ '0:0:0:0:0:0:0:0/19', '0:0:0:0:0:0:0:0' ], - '0:0:0:0:0:0:0:0', - '0:0:0:0:0:0:0:0' - ], 'Blocks to narrow IPv4 range and IP' => [ [ '0.0.0.0/31', '0.0.0.0' ], '0.0.0.0', '0.0.0.0' ], + 'Blocks to wide IPv6 range and IP' => [ + [ '0:0:0:0:0:0:0:0/19', '0:0:0:0:0:0:0:0' ], + '0:0:0:0:0:0:0:0', + '0:0:0:0:0:0:0:0' + ], 'Blocks to narrow IPv6 range and IP' => [ [ '0:0:0:0:0:0:0:0/127', '0:0:0:0:0:0:0:0' ], '0:0:0:0:0:0:0:0', '0:0:0:0:0:0:0:0' ], + 'Blocks to wide IPv6 range and IP, large numbers' => [ + [ '2000:DEAD:BEEF:A:0:0:0:0/19', '2000:DEAD:BEEF:A:0:0:0:0' ], + '2000:DEAD:BEEF:A:0:0:0:0', + '2000:DEAD:BEEF:A:0:0:0:0' + ], + 'Blocks to narrow IPv6 range and IP, large numbers' => [ + [ '2000:DEAD:BEEF:A:0:0:0:0/127', '2000:DEAD:BEEF:A:0:0:0:0' ], + '2000:DEAD:BEEF:A:0:0:0:0', + '2000:DEAD:BEEF:A:0:0:0:0' + ], ]; }