Fixes #16377: Fixed yii\base\Event:off() undefined index error when event handler does not match

This commit is contained in:
Razvan Grigore
2018-06-12 08:50:43 +02:00
committed by Alexander Makarov
parent 858d3531ed
commit ca3c8da503
3 changed files with 23 additions and 12 deletions

View File

@ -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
-----------------------

View File

@ -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;
}

View File

@ -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