apigility: filters in `input_filter_specs` not working
samsonasik opened this issue · 9 comments
Steps to reproduce:
- define
input_filter_specs
config:
'ApiName\\V1\\Rpc\\Register\\Validator' => array(
0 => array(
'required' => true,
'validators' => array(
0 => array(
'name' => 'Zend\\Validator\\StringLength',
'options' => array(
'min' => '1',
'max' => '100',
),
),
),
'filters' => array(
0 => array(
'name' => 'Zend\\Filter\\StringTrim',
'options' => array(),
),
),
'name' => 'name',
'description' => 'Version Name',
'error_message' => 'Invalid version name',
),
),
- try send name:
{ "name" : "foo " }
- try echo
echo $this->bodyParam('name');
in controller
echo $this->bodyParam('name'); // echoed 'foo ' with space in the right
with Zend\\Filter\\StringTrim
definition, when a field named name
sent with space in left and right, it should be trimmed, but at this case, it never trimmed. The validators
is working, the filter is not.
It happen with other filters too.
nvm, I should use $this->getInputFilter()->getValues() instead of $this->bodyParams();
Are you sure?
Should the body params not be pulled through the input-filter?
This reminds me of this issue: zfcampus/zf-apigility-skeleton#75
I don't know if that is on purpose as $this->bodyParams()
not include the inputfilter
Maybe good to reopen your issue and await feedback? I am kind of interested...
IMO it seems dangerous to end up with unfiltered data inside your controller.
re-open
@samsonasik @Wilt It is expected behaviour in apigility, please read this documentation:
https://apigility.org/documentation/content-validation/basic-usage#accessing-filtered-data
zf-content-validation
leaves the request intact once validation is complete.
If you want to get filtered data you have to get them from input filter.
Please have a look also on similar issue zfcampus/zf-apigility#45
and @weierophinney answers.
Thank you, re-closed.
@webimpress Thanks!