mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-14 22:30:27 +08:00
Fixes #16377: Fixed yii\base\Event:off()
undefined index error when event handler does not match
This commit is contained in:

committed by
Alexander Makarov

parent
858d3531ed
commit
ca3c8da503
@ -34,6 +34,7 @@ Yii Framework 2 Change Log
|
||||
- Bug #16301: Fixed `yii\web\User::setIdentity()` to clear access check cache while setting identity object to `null` (Izumi-kun)
|
||||
- Bug #16322: Fixed strings were not were not compared using timing attack resistant approach while CSRF token validation (samdark, Felix Wiedemann)
|
||||
- Chg #16192: `yii\db\Command::logQuery()` is now protected (drlibra)
|
||||
- Bug #16377: Fixed `yii\base\Event:off()` undefined index error when event handler does not match (razvanphp)
|
||||
|
||||
2.0.15.1 March 21, 2018
|
||||
-----------------------
|
||||
|
@ -164,6 +164,7 @@ class Event extends BaseObject
|
||||
|
||||
// wildcard event names
|
||||
$removed = false;
|
||||
if (isset(self::$_eventWildcards[$name][$class])) {
|
||||
foreach (self::$_eventWildcards[$name][$class] as $i => $event) {
|
||||
if ($event[0] === $handler) {
|
||||
unset(self::$_eventWildcards[$name][$class][$i]);
|
||||
@ -180,6 +181,7 @@ class Event extends BaseObject
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $removed;
|
||||
}
|
||||
|
@ -91,6 +91,14 @@ class EventTest extends TestCase
|
||||
$this->assertTrue(Event::hasHandlers('yiiunit\framework\base\SomeInterface', SomeInterface::EVENT_SUPER_EVENT));
|
||||
}
|
||||
|
||||
public function testOffUnmatchedHandler()
|
||||
{
|
||||
$this->assertFalse(Event::hasHandlers(Post::className(), 'afterSave'));
|
||||
Event::on(Post::className(), 'afterSave', [$this, 'bla-bla']);
|
||||
$this->assertFalse(Event::off(Post::className(), 'afterSave', [$this, 'bla-bla-bla']));
|
||||
$this->assertTrue(Event::off(Post::className(), 'afterSave', [$this, 'bla-bla']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testOn
|
||||
* @depends testHasHandlers
|
||||
|
Reference in New Issue
Block a user