octicon-rss(16/)
You've already forked yii2
mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-10 02:13:17 +08:00
Make 'safe' validator work on write-only properties
fixes #12605
This commit is contained in:
octicon-git-branch(16/)
octicon-tag(16/)
octicon-diff(16/tw-mr-1) 3 changed files with 40 additions and 1 deletions
@@ -44,9 +44,10 @@ Yii Framework 2 Change Log
|
|||||||
- Bug #12537: Fixes issues with spaces in `StringHelper:truncateHtml` (Alex-Code)
|
- Bug #12537: Fixes issues with spaces in `StringHelper:truncateHtml` (Alex-Code)
|
||||||
- Bug #12554: Fixed `yii\validators\UniqueValidator` error of getting first model indexed by field (DrDeath72)
|
- Bug #12554: Fixed `yii\validators\UniqueValidator` error of getting first model indexed by field (DrDeath72)
|
||||||
- Bug #12599: Fixed casting of `binary()` type for MSSQL (silverfire)
|
- Bug #12599: Fixed casting of `binary()` type for MSSQL (silverfire)
|
||||||
|
- Bug #12605: Make 'safe' validator work on write-only properties (arthibald, CeBe)
|
||||||
- Bug #12629: Fixed `yii\widgets\ActiveField::widget()` to call `adjustLabelFor()` for `InputWidget` descendants (coderlex)
|
- Bug #12629: Fixed `yii\widgets\ActiveField::widget()` to call `adjustLabelFor()` for `InputWidget` descendants (coderlex)
|
||||||
- Bug #12649: Fixed consistency of `indexBy` handling for `yii\db\Query::column()` (silverfire)
|
- Bug #12649: Fixed consistency of `indexBy` handling for `yii\db\Query::column()` (silverfire)
|
||||||
- Enh #384: Added ability to run migration from several locations via `yii\console\controllers\BaseMigrateController::migrationNamespaces` (klimov-paul)
|
- Enh #384: Added ability to run migration from several locations via `yii\console\controllers\BaseMigrateController::$migrationNamespaces` (klimov-paul)
|
||||||
- Enh #6996: Added `yii\web\MultipartFormDataParser`, which allows proper processing of 'multipart/form-data' encoded non POST requests (klimov-paul)
|
- Enh #6996: Added `yii\web\MultipartFormDataParser`, which allows proper processing of 'multipart/form-data' encoded non POST requests (klimov-paul)
|
||||||
- Enh #8719: Add support for HTML5 attributes on submitbutton (formaction/formmethod...) for ActiveForm (VirtualRJ)
|
- Enh #8719: Add support for HTML5 attributes on submitbutton (formaction/formmethod...) for ActiveForm (VirtualRJ)
|
||||||
- Enh #9469: Added support for namespaced migrations via `yii\console\controllers\BaseMigrateController::migrationNamespaces` (klimov-paul)
|
- Enh #9469: Added support for namespaced migrations via `yii\console\controllers\BaseMigrateController::migrationNamespaces` (klimov-paul)
|
||||||
|
|||||||
@@ -23,6 +23,13 @@ namespace yii\validators;
|
|||||||
*/
|
*/
|
||||||
class SafeValidator extends Validator
|
class SafeValidator extends Validator
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function validateAttributes($model, $attributes = null)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -398,6 +398,20 @@ class ModelTest extends TestCase
|
|||||||
$invalid = new InvalidRulesModel();
|
$invalid = new InvalidRulesModel();
|
||||||
$invalid->createValidators();
|
$invalid->createValidators();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure 'safe' validator works for write-only properties.
|
||||||
|
* Normal validator can not work here though.
|
||||||
|
*/
|
||||||
|
public function testValidateWriteOnly()
|
||||||
|
{
|
||||||
|
$model = new WriteOnlyModel();
|
||||||
|
|
||||||
|
$model->setAttributes(['password' => 'test'], true);
|
||||||
|
$this->assertEquals('test', $model->passwordHash);
|
||||||
|
|
||||||
|
$this->assertTrue($model->validate());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ComplexModel1 extends Model
|
class ComplexModel1 extends Model
|
||||||
@@ -423,3 +437,20 @@ class ComplexModel2 extends Model
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class WriteOnlyModel extends Model
|
||||||
|
{
|
||||||
|
public $passwordHash;
|
||||||
|
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[['password'],'safe'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPassword($pw)
|
||||||
|
{
|
||||||
|
$this->passwordHash = $pw;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user