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
42 stars 28 forks source link

Inputfilter getValues() returns the field which is not in input data #9

Open weierophinney opened 4 years ago

weierophinney commented 4 years ago
$specs =  array(
    'title' => array(
        'name'       => 'title',
        'filters' => array(
            array(
                'name' => 'Zend\Filter\StringToLower',
            ),
        ),
    ),
);

$inputFilterFactory = new \Zend\InputFilter\Factory();
$inputFilter = $inputFilterFactory->createInputFilter($specs);
$data = array(
    'title' => 'TEST',
);
$inputFilter->setData($data);
var_dump($inputFilter->getValues());

Expected Output:

array(1) {
  ["title"]=>
  string(3) "test"
}
$data = array(
    'xyz' => 'something',
);
$inputFilter->setData($data);
var_dump($inputFilter->getValues());

Unexpected (or it is intentional?) Output:

array(1) {
  ["title"]=> NULL
}

Originally posted by @metanav at https://github.com/zendframework/zend-inputfilter/issues/66

weierophinney commented 4 years ago

Related to https://github.com/zendframework/zf2/issues/7440


Originally posted by @Maks3w at https://github.com/zendframework/zend-inputfilter/issues/66#issuecomment-137972236

weierophinney commented 4 years ago

One possible option is to add an argument to getValues() for to return all inputs or only the inputs with data set.


Originally posted by @Maks3w at https://github.com/zendframework/zend-inputfilter/issues/66#issuecomment-137972377

weierophinney commented 4 years ago

Another option is add a new method for return only the fields with data (method name is more expressive rather than arguments values).


Originally posted by @Maks3w at https://github.com/zendframework/zend-inputfilter/issues/66#issuecomment-137972587

weierophinney commented 4 years ago

That would not stop input filter to do filtering of the input which is not set. The new method would just do one more filtering of unset data.


Originally posted by @metanav at https://github.com/zendframework/zend-inputfilter/issues/66#issuecomment-137973363