Skip to content

Commit 6abe5bf

Browse files
authored
Fix #20232: Fix regression introduced in GHSA-cjcc-p67m-7qxm while attaching behavior defined by __class array key
1 parent 633998b commit 6abe5bf

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

framework/CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ Yii Framework 2 Change Log
44
2.0.52 under development
55
------------------------
66

7-
- no changes in this release.
8-
7+
- Bug #20232: Fix regression introduced in `GHSA-cjcc-p67m-7qxm` while attaching behavior defined by `__class` array key (erickskrauch)
98

109
2.0.51 July 18, 2024
1110
--------------------

framework/base/Component.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public function __set($name, $value)
190190
$name = trim(substr($name, 3));
191191
if ($value instanceof Behavior) {
192192
$this->attachBehavior($name, $value);
193-
} elseif (isset($value['class']) && is_subclass_of($value['class'], Behavior::class, true)) {
193+
} elseif ((isset($value['class']) && is_subclass_of($value['class'], Behavior::class)) || (isset($value['__class']) && is_subclass_of($value['__class'], Behavior::class))) {
194194
$this->attachBehavior($name, Yii::createObject($value));
195195
} elseif (is_string($value) && is_subclass_of($value, Behavior::class, true)) {
196196
$this->attachBehavior($name, Yii::createObject($value));

tests/framework/base/ComponentTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,9 @@ public function testAttachBehavior()
341341
$this->assertTrue($component->hasProperty('p'));
342342
$component->test();
343343
$this->assertTrue($component->behaviorCalled);
344+
345+
$component->{'as c'} = ['__class' => NewBehavior::class];
346+
$this->assertNotNull($component->getBehavior('c'));
344347
}
345348

346349
public function testAttachBehaviors()

0 commit comments

Comments
 (0)