laminas / laminas-inputfilter

Normalize and validate input sets from the web, APIs, the CLI, and more, including files
https://docs.laminas.dev/laminas-inputfilter/
BSD 3-Clause "New" or "Revised" License
41 stars 28 forks source link

Array Input has strange behaviour #104

Closed gsteel closed 5 months ago

gsteel commented 5 months ago

I would expect that using an ArrayInput with InputFilter to fail validation when given non-array input, but instead an exception is thrown.

Given that the whole idea is filtering and validation of untrusted input, causing a crash in this situation seems odd to me.

$inputFilter = new InputFilter();
$inputFilter->add([
    'type'       => ArrayInput::class,
    'validators' => [
        ['name' => NotEmptyValidator::class],
    ],
], 'myInput');

$inputFilter->setData(['myInput' => 'Whatever']); // Exception thrown here.
assert($inputFilter->isValid() === false);