Browse Source

Fixes #17377: Add tests that verify there are no false positives

tags/2.0.21
Alexander Makarov 5 years ago
parent
commit
1c919a5ac5
No known key found for this signature in database
GPG Key ID: 3617B79C6A325E4A
  1. 2
      framework/base/Event.php
  2. 11
      tests/framework/base/EventTest.php

2
framework/base/Event.php

@ -233,7 +233,7 @@ class Event extends BaseObject
// wildcard events
foreach (self::$_eventWildcards as $nameWildcard => $classHandlers) {
if (!StringHelper::matchWildcard($nameWildcard, $name)) {
if (!StringHelper::matchWildcard($nameWildcard, $name, ['escape' => false])) {
continue;
}
foreach ($classHandlers as $classWildcard => $handlers) {

11
tests/framework/base/EventTest.php

@ -103,6 +103,17 @@ class EventTest extends TestCase
$this->assertTrue(Event::hasHandlers('yiiunit\framework\base\SomeInterface', 'save.it'), 'save.it');
}
/**
* @see https://github.com/yiisoft/yii2/issues/17377
*/
public function testNoFalsePositivesWithHasHandlers()
{
$this->assertFalse(Event::hasHandlers(new \stdClass(), 'foobar'));
$component = new Component();
$this->assertFalse($component->hasEventHandlers('foobar'));
}
public function testOffUnmatchedHandler()
{
$this->assertFalse(Event::hasHandlers(Post::className(), 'afterSave'));

Loading…
Cancel
Save