Skip to content

Commit f0ce06a

Browse files
authored
Fix parameters leak in context validation (#720)
1 parent e8d9505 commit f0ce06a

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## 1.4.1 under development
44

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

77
## 1.4.0 May 22, 2024
88

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"maglnet/composer-require-checker": "^4.3",
4343
"phpbench/phpbench": "^1.2",
4444
"phpunit/phpunit": "^9.5",
45-
"rector/rector": "^1.0",
45+
"rector/rector": "1.0.*",
4646
"roave/infection-static-analysis-plugin": "^1.25",
4747
"spatie/phpunit-watcher": "^1.23",
4848
"vimeo/psalm": "^4.30|^5.22",

src/ValidationContext.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ public function validate(mixed $data, callable|iterable|object|string|null $rule
146146
$currentDataSet = $this->dataSet;
147147
$currentAttribute = $this->attribute;
148148
$isCurrentDataSetMissing = $this->isDataSetMissing;
149+
$currentParameters = $this->parameters;
149150

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

158160
return $result;
159161
}

tests/Rule/EachTest.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Generator;
88
use Yiisoft\Validator\Result;
9+
use Yiisoft\Validator\Rule\Callback;
910
use Yiisoft\Validator\Rule\Each;
1011
use Yiisoft\Validator\Rule\EachHandler;
1112
use Yiisoft\Validator\Rule\Length;
@@ -170,10 +171,31 @@ public function testGetOptionsWithNotRule(): void
170171
public function dataValidationPassed(): array
171172
{
172173
return [
173-
[
174+
'base' => [
174175
[10, 11],
175176
[new Each([new Number(max: 20)])],
176177
],
178+
'double-each-with-arrays' => [
179+
[
180+
'items' => [
181+
['variantId' => 123, 'quantity' => 1],
182+
],
183+
],
184+
[
185+
'items' => [
186+
new Each([
187+
new Callback(callback: function (array $item) {
188+
return new Result();
189+
}),
190+
]),
191+
new Each([
192+
new Callback(callback: function (array $item) {
193+
return new Result();
194+
}),
195+
]),
196+
],
197+
],
198+
],
177199
];
178200
}
179201

0 commit comments

Comments
 (0)