Skip to content

Commit

Permalink
Merge pull request #2 from dealnews/fix_urls_in_arrays_not_being_trimmed
Browse files Browse the repository at this point in the history
Update values in the array when the values of the array are checked
  • Loading branch information
brianlmoon authored Jan 19, 2024
2 parents 4e29a24 + de3d3ac commit f8d5d27
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Constraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ public function filterPrimitive($value, string $type, array $constraint, array $
}
if (is_array($new_value) && !empty($constraint['constraint'])) {
try {
foreach ($new_value as $nv) {
$this->check($nv, $constraint['constraint']);
foreach ($new_value as $k => $nv) {
$new_value[$k] = $this->check($nv, $constraint['constraint']);
}
} catch (ConstraintException $e) {
$new_value = null;
Expand Down
5 changes: 5 additions & 0 deletions tests/Constraint/URLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public function constraintData() {
['type' => 'url'],
'http://www.example.com/',
],
[
"http://www.example.com/ ",
["type" => "url"],
"http://www.example.com/"
],
[
' ',
['type' => 'url'],
Expand Down
16 changes: 16 additions & 0 deletions tests/ConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,22 @@ public function successData() {
],
[1,2,3]
],
[
[
'https://www.example.com',
'https://www.example.com ',
],
[
'type' => 'array',
'constraint' => [
'type' => 'url',
],
],
[
'https://www.example.com',
'https://www.example.com',
],
],
[
new \ArrayObject(),
[
Expand Down

0 comments on commit f8d5d27

Please sign in to comment.