Skip to content

Commit

Permalink
Fix wrong handling of null values when Unique::fields is set
Browse files Browse the repository at this point in the history
  • Loading branch information
plfort committed Jan 9, 2023
1 parent 0f38c5a commit 2b652bd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Constraints/UniqueValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private function reduceElementKeys(array $fields, array $element): array
if (!\is_string($field)) {
throw new UnexpectedTypeException($field, 'string');
}
if (isset($element[$field])) {
if (\array_key_exists($field, $element)) {
$output[$field] = $element[$field];
}
}
Expand Down
8 changes: 8 additions & 0 deletions Tests/Constraints/UniqueValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,14 @@ public function getInvalidCollectionValues(): array
['id' => 1, 'email' => '[email protected]'],
['id' => 1, 'email' => '[email protected]'],
], ['id']],
'unique null' => [
[null, null],
[],
],
'unique field null' => [
[['nullField' => null], ['nullField' => null]],
['nullField'],
],
];
}
}
Expand Down

0 comments on commit 2b652bd

Please sign in to comment.