From 2a742cee9fa9a22fd0a2a8eba69b3ca42fa4114b Mon Sep 17 00:00:00 2001 From: Klimov Paul Date: Wed, 3 Jan 2018 15:46:15 +0200 Subject: [PATCH] Fixed `yii\behaviors\AttributeTypecastBehavior::$attributeTypes` auto-detection fails for rule, which specify attribute with '!' prefix --- framework/CHANGELOG.md | 1 + framework/behaviors/AttributeTypecastBehavior.php | 2 +- tests/framework/behaviors/AttributeTypecastBehaviorTest.php | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index ce18561bf2d..b9716633828 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -26,6 +26,7 @@ Yii Framework 2 Change Log - Bug #15380: `FormatConverter::convertDateIcuToPhp()` now converts `a` ICU symbols to `A` (brandonkelly) - Bug #15407: Fixed rendering rows with associative arrays in `yii\console\widgets\Table` (dmrogin) - Bug #15432: Fixed wrong value being set in `yii\filters\RateLimiter::checkRateLimit()` resulting in wrong `X-Rate-Limit-Reset` header value (bizley) +- Bug #15440: Fixed `yii\behaviors\AttributeTypecastBehavior::$attributeTypes` auto-detection fails for rule, which specify attribute with '!' prefix (klimov-paul) - Enh #3087: Added `yii\helpers\BaseHtml::error()` "errorSource" option to be able to customize errors display (yanggs07, developeruz, silverfire) - Enh #3250: Added support for events partial wildcard matching (klimov-paul) - Enh #5515: Added default value for `yii\behaviors\BlameableBehavior` for cases when the user is guest (dmirogin) diff --git a/framework/behaviors/AttributeTypecastBehavior.php b/framework/behaviors/AttributeTypecastBehavior.php index 4986aaa3111..cfc600d9eae 100644 --- a/framework/behaviors/AttributeTypecastBehavior.php +++ b/framework/behaviors/AttributeTypecastBehavior.php @@ -285,7 +285,7 @@ protected function detectAttributeTypes() if ($type !== null) { foreach ((array) $validator->attributes as $attribute) { - $attributeTypes[$attribute] = $type; + $attributeTypes[ltrim($attribute, '!')] = $type; } } } diff --git a/tests/framework/behaviors/AttributeTypecastBehaviorTest.php b/tests/framework/behaviors/AttributeTypecastBehaviorTest.php index 85c8a609fa2..a74300df48a 100644 --- a/tests/framework/behaviors/AttributeTypecastBehaviorTest.php +++ b/tests/framework/behaviors/AttributeTypecastBehaviorTest.php @@ -141,7 +141,7 @@ public function testAutoDetectAttributeTypes() ->addRule('name', 'string') ->addRule('amount', 'integer') ->addRule('price', 'number') - ->addRule('isActive', 'boolean'); + ->addRule('!isActive', 'boolean'); $behavior = new AttributeTypecastBehavior();