diff --git a/src/Constraint.php b/src/Constraint.php index f3e2dad..84cc210 100644 --- a/src/Constraint.php +++ b/src/Constraint.php @@ -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; diff --git a/tests/Constraint/URLTest.php b/tests/Constraint/URLTest.php index 0e5fb6c..9b8830c 100644 --- a/tests/Constraint/URLTest.php +++ b/tests/Constraint/URLTest.php @@ -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'], diff --git a/tests/ConstraintTest.php b/tests/ConstraintTest.php index 338505b..9afda20 100644 --- a/tests/ConstraintTest.php +++ b/tests/ConstraintTest.php @@ -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(), [