Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf6217d8

Browse files
committed
[Validator] Fix fields without constraints inCollection
1 parentb341535 commitf6217d8

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

‎src/Symfony/Component/Validator/Constraints/Collection.php‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,20 @@ private static function isFieldsOption($options): bool
9494
returnfalse;
9595
}
9696

97-
if ([] ===$options) {
98-
returntrue;
99-
}
100-
10197
foreach ($optionsas$optionOrField) {
10298
if ($optionOrFieldinstanceof Constraint) {
10399
returntrue;
104100
}
105101

102+
if (null ===$optionOrField) {
103+
continue;
104+
}
105+
106106
if (!\is_array($optionOrField)) {
107107
returnfalse;
108108
}
109109

110-
if ([] !==$optionOrField && !($optionOrField[0] ??null)instanceof Constraint) {
110+
if ($optionOrField && !($optionOrField[0] ??null)instanceof Constraint) {
111111
returnfalse;
112112
}
113113
}

‎src/Symfony/Component/Validator/Tests/Constraints/CollectionTest.php‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,15 @@ public function testEmptyFieldsInOptions()
175175
$this->assertSame('foo bar baz',$constraint->extraFieldsMessage);
176176
}
177177

178-
publicfunctiontestEmptyConstraintListFor()
178+
/**
179+
* @testWith [[]]
180+
* [null]
181+
*/
182+
publicfunctiontestEmptyConstraintListForField(?array$fieldConstraint)
179183
{
180-
$constraint =newCollection([
181-
'foo' => [],
184+
$constraint =newCollection(
185+
[
186+
'foo' =>$fieldConstraint,
182187
],
183188
null,
184189
null,
@@ -193,11 +198,15 @@ public function testEmptyConstraintListFor()
193198
$this->assertSame('foo bar baz',$constraint->extraFieldsMessage);
194199
}
195200

196-
publicfunctiontestEmptyConstraintListForFieldInOptions()
201+
/**
202+
* @testWith [[]]
203+
* [null]
204+
*/
205+
publicfunctiontestEmptyConstraintListForFieldInOptions(?array$fieldConstraint)
197206
{
198207
$constraint =newCollection([
199208
'fields' => [
200-
'foo' =>[],
209+
'foo' =>$fieldConstraint,
201210
],
202211
'allowExtraFields' =>true,
203212
'extraFieldsMessage' =>'foo bar baz',

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp