mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-04 22:57:40 +08:00
Fixes #14033: Fixed yii\filters\AccessRule::matchIp() erroring in case IP is not defined under HHVM
This commit is contained in:
committed by
Alexander Makarov
parent
d786b78f25
commit
1e65fc29ed
@ -4,6 +4,7 @@ Yii Framework 2 Change Log
|
|||||||
2.0.12 under development
|
2.0.12 under development
|
||||||
--------------------------
|
--------------------------
|
||||||
|
|
||||||
|
- Bug #14033: Fixed `yii\filters\AccessRule::matchIp()` erroring in case IP is not defined under HHVM (Kolyunya)
|
||||||
- Bug #13848: `yii\di\Instance::ensure()` wasn't throwing an exception when `$type` is specified and `$reference` object isn't instance of `$type` (c-jonua)
|
- Bug #13848: `yii\di\Instance::ensure()` wasn't throwing an exception when `$type` is specified and `$reference` object isn't instance of `$type` (c-jonua)
|
||||||
- Enh #13226: `yii cache` command now warns about the fact that it's not able to flush APC cache from console (samdark)
|
- Enh #13226: `yii cache` command now warns about the fact that it's not able to flush APC cache from console (samdark)
|
||||||
- Bug #13689: Fixed handling of errors in closures (mikehaertl)
|
- Bug #13689: Fixed handling of errors in closures (mikehaertl)
|
||||||
|
|||||||
@ -165,7 +165,7 @@ class AccessRule extends Component
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $ip the IP address
|
* @param string|null $ip the IP address
|
||||||
* @return bool whether the rule applies to the IP address
|
* @return bool whether the rule applies to the IP address
|
||||||
*/
|
*/
|
||||||
protected function matchIP($ip)
|
protected function matchIP($ip)
|
||||||
@ -174,7 +174,14 @@ class AccessRule extends Component
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
foreach ($this->ips as $rule) {
|
foreach ($this->ips as $rule) {
|
||||||
if ($rule === '*' || $rule === $ip || (($pos = strpos($rule, '*')) !== false && !strncmp($ip, $rule, $pos))) {
|
if ($rule === '*' ||
|
||||||
|
$rule === $ip ||
|
||||||
|
(
|
||||||
|
$ip !== null &&
|
||||||
|
($pos = strpos($rule, '*')) !== false &&
|
||||||
|
strncmp($ip, $rule, $pos) === 0
|
||||||
|
)
|
||||||
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -292,6 +292,14 @@ class AccessRuleTest extends \yiiunit\TestCase
|
|||||||
$this->assertNull($rule->allows($action, $user, $request));
|
$this->assertNull($rule->allows($action, $user, $request));
|
||||||
$rule->allow = false;
|
$rule->allow = false;
|
||||||
$this->assertNull($rule->allows($action, $user, $request));
|
$this->assertNull($rule->allows($action, $user, $request));
|
||||||
|
|
||||||
|
// undefined IP
|
||||||
|
$_SERVER['REMOTE_ADDR'] = null;
|
||||||
|
$rule->ips = ['192.168.*'];
|
||||||
|
$rule->allow = true;
|
||||||
|
$this->assertNull($rule->allows($action, $user, $request));
|
||||||
|
$rule->allow = false;
|
||||||
|
$this->assertNull($rule->allows($action, $user, $request));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMatchIPWildcard()
|
public function testMatchIPWildcard()
|
||||||
|
|||||||
Reference in New Issue
Block a user