Index: trunk/phase3/tests/phpunit/includes/BlockTest.php |
— | — | @@ -48,5 +48,38 @@ |
49 | 49 | |
50 | 50 | } |
51 | 51 | |
| 52 | + /** |
| 53 | + * This is the method previously used to load block info in CheckUser etc |
| 54 | + * passing an empty value (empty string, null, etc) as the ip parameter bypasses IP lookup checks. |
| 55 | + * |
| 56 | + * This stopped working with r84475 and friends: regression being fixed for bug 29116. |
| 57 | + * |
| 58 | + * @dataProvider dataBug29116 |
| 59 | + */ |
| 60 | + function testBug29116LoadWithEmptyIp( $vagueTarget ) { |
| 61 | + $block = new Block(); |
| 62 | + $block->load( $vagueTarget, 'UTBlockee' ); |
| 63 | + $this->assertTrue( $this->block->equals( Block::newFromTarget('UTBlockee', $vagueTarget) ), "Block->load() returns the same block as the one that was made when given empty ip param " . var_export( $vagueTarget, true ) ); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * CheckUser since being changed to use Block::newFromTarget started failing |
| 68 | + * because the new function didn't accept empty strings like Block::load() |
| 69 | + * had. Regression bug 29116. |
| 70 | + * |
| 71 | + * @dataProvider dataBug29116 |
| 72 | + */ |
| 73 | + function testBug29116NewFromTargetWithEmptyIp( $vagueTarget ) { |
| 74 | + $block = Block::newFromTarget('UTBlockee', $vagueTarget); |
| 75 | + $this->assertTrue( $this->block->equals( $block ), "newFromTarget() returns the same block as the one that was made when given empty vagueTarget param " . var_export( $vagueTarget, true ) ); |
| 76 | + } |
| 77 | + |
| 78 | + function dataBug29116() { |
| 79 | + return array( |
| 80 | + array( null ), |
| 81 | + array( '' ), |
| 82 | + array( false ) |
| 83 | + ); |
| 84 | + } |
52 | 85 | } |
53 | 86 | |
Index: trunk/phase3/includes/Block.php |
— | — | @@ -184,7 +184,7 @@ |
185 | 185 | * 2) A rangeblock encompasing the given IP (smallest first) |
186 | 186 | * 3) An autoblock on the given IP |
187 | 187 | * @param $vagueTarget User|String also search for blocks affecting this target. Doesn't |
188 | | - * make any sense to use TYPE_AUTO / TYPE_ID here |
| 188 | + * make any sense to use TYPE_AUTO / TYPE_ID here. Leave blank to skip IP lookups. |
189 | 189 | * @return Bool whether a relevant block was found |
190 | 190 | */ |
191 | 191 | protected function newLoad( $vagueTarget = null ) { |
— | — | @@ -198,7 +198,8 @@ |
199 | 199 | $conds = array( 'ipb_address' => array() ); |
200 | 200 | } |
201 | 201 | |
202 | | - if( $vagueTarget !== null ){ |
| 202 | + # Be aware that the != '' check is explicit, since empty values will be passed by some callers. |
| 203 | + if( $vagueTarget != ''){ |
203 | 204 | list( $target, $type ) = self::parseTarget( $vagueTarget ); |
204 | 205 | switch( $type ) { |
205 | 206 | case self::TYPE_USER: |
— | — | @@ -962,7 +963,7 @@ |
963 | 964 | * 1.2.3.4 will not select 1.2.0.0/16 or even 1.2.3.4/32) |
964 | 965 | * @param $vagueTarget String|User|Int as above, but we will search for *any* block which |
965 | 966 | * affects that target (so for an IP address, get ranges containing that IP; and also |
966 | | - * get any relevant autoblocks) |
| 967 | + * get any relevant autoblocks). Leave empty or blank to skip IP-based lookups. |
967 | 968 | * @param $fromMaster Bool whether to use the DB_MASTER database |
968 | 969 | * @return Block|null (null if no relevant block could be found). The target and type |
969 | 970 | * of the returned Block will refer to the actual block which was found, which might |
— | — | @@ -979,8 +980,9 @@ |
980 | 981 | if( $type == Block::TYPE_ID || $type == Block::TYPE_AUTO ){ |
981 | 982 | return Block::newFromID( $target ); |
982 | 983 | |
983 | | - } elseif( $target === null && $vagueTarget === null ){ |
| 984 | + } elseif( $target === null && $vagueTarget == '' ){ |
984 | 985 | # We're not going to find anything useful here |
| 986 | + # Be aware that the == '' check is explicit, since empty values will be passed by some callers. |
985 | 987 | return null; |
986 | 988 | |
987 | 989 | } elseif( in_array( $type, array( Block::TYPE_USER, Block::TYPE_IP, Block::TYPE_RANGE, null ) ) ) { |