Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parameters leak in context validation #720

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 1.4.1 under development

- no changes in this release.
- Bug #719: Fix parameters leak in context validation (@vjik)

## 1.4.0 May 22, 2024

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"maglnet/composer-require-checker": "^4.3",
"phpbench/phpbench": "^1.2",
"phpunit/phpunit": "^9.5",
"rector/rector": "^1.0",
"rector/rector": "1.0.*",
"roave/infection-static-analysis-plugin": "^1.25",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.30|^5.22",
Expand Down
2 changes: 2 additions & 0 deletions src/ValidationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public function validate(mixed $data, callable|iterable|object|string|null $rule
$currentDataSet = $this->dataSet;
$currentAttribute = $this->attribute;
$isCurrentDataSetMissing = $this->isDataSetMissing;
$currentParameters = $this->parameters;

// The lack of an attribute means that in the context of further validation there is no data set at all.
$this->isDataSetMissing = $this->isAttributeMissing();
Expand All @@ -154,6 +155,7 @@ public function validate(mixed $data, callable|iterable|object|string|null $rule
$this->dataSet = $currentDataSet;
$this->attribute = $currentAttribute;
$this->isDataSetMissing = $isCurrentDataSetMissing;
$this->parameters = $currentParameters;

return $result;
}
Expand Down
24 changes: 23 additions & 1 deletion tests/Rule/EachTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Generator;
use Yiisoft\Validator\Result;
use Yiisoft\Validator\Rule\Callback;
use Yiisoft\Validator\Rule\Each;
use Yiisoft\Validator\Rule\EachHandler;
use Yiisoft\Validator\Rule\Length;
Expand Down Expand Up @@ -170,10 +171,31 @@ public function testGetOptionsWithNotRule(): void
public function dataValidationPassed(): array
{
return [
[
'base' => [
[10, 11],
[new Each([new Number(max: 20)])],
],
'double-each-with-arrays' => [
[
'items' => [
['variantId' => 123, 'quantity' => 1],
],
],
[
'items' => [
new Each([
new Callback(callback: function (array $item) {
return new Result();
}),
]),
new Each([
new Callback(callback: function (array $item) {
return new Result();
}),
]),
],
],
],
];
}

Expand Down
Loading