Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

BC in validators context value #16

Closed
svycka opened this issue Aug 12, 2015 · 7 comments · Fixed by #24
Closed

BC in validators context value #16

svycka opened this issue Aug 12, 2015 · 7 comments · Fixed by #24
Labels
Milestone

Comments

@svycka
Copy link
Contributor

svycka commented Aug 12, 2015

Before 2.5.2 context values was all inputs added to inputfilter but 2.5.2 changed this and now returns raw values passed to inputFilter. I Think this should be and is correct behavior, but unfortunately now it is BC. This should be at least mentioned in release notes or fixed.

example:

<?php

require __DIR__ . '/vendor/autoload.php';

class MyFilter extends Zend\InputFilter\InputFilter
{
    public function init()
    {
        $this->add([
            'name' => 'field1',
            'required' => true,
        ]);

        $this->add([
            'name' => 'field2',
            'required' => true,
            'validators' => [
                [
                    'name' => 'Zend\Validator\Callback',
                    'options'  => [
                        'callback' => function ($value, $context) {
                            var_dump($context);
                            return true;
                        },
                    ],
                ],
            ],
        ]);
    }
}

$app = Zend\Mvc\Application::init([
    'modules' => [
    ],

    'module_listener_options' => [
        'module_paths' => [
        ],

        'config_glob_paths' => [
        ],
    ],

    'input_filters' => [
        'invokables' => [
            'MyFilter' => 'MyFilter',
        ],
    ],
]);

$manager = $app->getServiceManager()->get('InputFilterManager');
$filter = $manager->get('MyFilter');

echo "\n";
echo "#------------------------------\n";
echo "# Test case\n";
echo "#------------------------------\n";
echo "\n";
$filter->setData([
    'field2' => 'foo',
]);

$filter->isValid();

output with versions =<2.5.1

#------------------------------
# Test case
#------------------------------

array(2) {
  'field1' =>
  NULL
  'field2' =>
  string(3) "foo"
}

output with versions =>2.5.2

#------------------------------
# Test case
#------------------------------

array(1) {
  'field2' =>
  string(3) "foo"
}
@svycka
Copy link
Contributor Author

svycka commented Aug 17, 2015

@Maks3w do you think this should be fixed or not? This holding me from updating.
@weierophinney what do you think? It seems that your fix for another bug introduced this.

@marcuswinkler
Copy link

I just want to note that this was reverting behavior back to where it was in 2.2.4 and before. See zendframework/zendframework#6264

So:

version result
<= 2.2.4 raw values get passed as context
>= 2.2.5 && <= 2.5.1 values extracted from inputs get passed as context
>= 2.5.2 raw values get passed as context

@svycka
Copy link
Contributor Author

svycka commented Aug 19, 2015

Even more fun :) then maybe time to take final decision on this and add some tests.

@Maks3w
Copy link
Member

Maks3w commented Aug 20, 2015

@svycka I don't understand your example. Your code does not use any of getXValue method. What method is giving you troubles?

@svycka
Copy link
Contributor Author

svycka commented Aug 20, 2015

@Maks3w problem is not the getXValue methods but the context passed to validators. It varies between versions.
Example shows that when I have input filter with two inputs and I provide data for one input, as context in validators I don't get both values. But with older versions of zend-inputfilter there would be both in context.

//simplified example
$inputFilter = ['A', 'B']; // A, B inputs
$inputFilter->setData(['B' => null]);

then when validating B validators as context gets ['B' => null]
when in older versions it would be ['A' => null, 'B' => null]

Also @marcuswinkler noted that this change happened not the first time.

@Maks3w
Copy link
Member

Maks3w commented Aug 20, 2015

Ahm. Seems I found the same issue today while reviewing the code. #24

@Maks3w
Copy link
Member

Maks3w commented Aug 20, 2015

@svycka Could you review #24

Maks3w added a commit to Maks3w/zend-inputfilter that referenced this issue Aug 20, 2015
Maks3w added a commit to Maks3w/zend-inputfilter that referenced this issue Aug 20, 2015
@Maks3w Maks3w added the bug label Aug 21, 2015
@Maks3w Maks3w added this to the 2.4.8 milestone Aug 21, 2015
Maks3w added a commit to Maks3w/zend-inputfilter that referenced this issue Aug 24, 2015
Maks3w added a commit to Maks3w/zend-inputfilter that referenced this issue Aug 24, 2015
Maks3w added a commit to Maks3w/zend-inputfilter that referenced this issue Aug 27, 2015
Maks3w added a commit to Maks3w/zend-inputfilter that referenced this issue Sep 1, 2015
weierophinney added a commit that referenced this issue Sep 1, 2015
weierophinney added a commit to weierophinney/zend-inputfilter that referenced this issue Sep 8, 2015
Includes these changes:

- [14: NotEmpty validator doesn't override the required attribute](zendframework#14)
- [16: BC in validators context value](zendframework#16)
- [22: Missing required field with fallback does not return input in getValidInput](zendframework#22)
- [24: Fix loop validation input context is mutable](zendframework#24)
- [25: Fix missing optional fields should not be validated](zendframework#25)
- [32: Promote HHVM](zendframework#32)
- [36: Fix docblocks declared as regular comment block](zendframework#36)
- [40: Remove test about Input setters permutation](zendframework#40)
- [41: Refactor tests for group 7448 as a data set matrix](zendframework#41)
- [42: Consolidate InputFilterPluginManager tests](zendframework#42)
- [43: Consolidate Factory tests + Fixes](zendframework#43)
- [44: Consolidate of InputInterface::merge and Fix unsafe merge](zendframework#44)
- [45: When merge Inputs don't merge values if source does not have one.](zendframework#45)
- [46: Expand test matrix with nonempty value scenarios](zendframework#46)
- [47: Feature/minor test improvements](zendframework#47)
- [48: Empty values + Allow Empty + Not continue if empty is always true](zendframework#48)
- [49: Add tests for exceptions and improve some messages](zendframework#49)
- [50: Optional fields without value should be valid ](zendframework#50)
- [51: Optional input without value are valid](zendframework#51)
- [52: Fix merge two inputs without value, result 'has value' flag should be false](zendframework#52)
- [53: Tune NonEmpty options for detect the expected empty values](zendframework#53)
- [55: Make symmetric the scenarios when required is true/false](zendframework#55)
- [56: Hotfix/minor changes](zendframework#56)
- [57: Consolidate tests for InputFilterInterface](zendframework#57)
- [61: Provide NotEmpty::IS&zendframework#95;EMPTY validation message for required input](zendframework#61)
- [63: Ensure custom error messages are used for required missing inputs](zendframework#63)
- [64: Feature/test cleanup](zendframework#64)
weierophinney added a commit to weierophinney/zend-inputfilter that referenced this issue Sep 9, 2015
Includes these changes:

- [14: NotEmpty validator doesn't override the required attribute](zendframework#14)
- [16: BC in validators context value](zendframework#16)
- [24: Fix loop validation input context is mutable](zendframework#24)
- [25: Fix missing optional fields should not be validated](zendframework#25)
- [26: Deprecate magic logic for auto attaching a NonEmpty validator with breakChainOnFailure = true](zendframework#26)
- [31: Update the InputFilterInterface::add docblock to match existing, shipped implementations](zendframework#31)
- [32: Promote HHVM](zendframework#32)
- [36: Fix docblocks declared as regular comment block](zendframework#36)
- [40: Remove test about Input setters permutation](zendframework#40)
- [41: Refactor tests for group 7448 as a data set matrix](zendframework#41)
- [42: Consolidate InputFilterPluginManager tests](zendframework#42)
- [43: Consolidate Factory tests + Fixes](zendframework#43)
- [44: Consolidate of InputInterface::merge and Fix unsafe merge](zendframework#44)
- [45: When merge Inputs don't merge values if source does not have one.](zendframework#45)
- [46: Expand test matrix with nonempty value scenarios](zendframework#46)
- [47: Feature/minor test improvements](zendframework#47)
- [48: Empty values + Allow Empty + Not continue if empty is always true](zendframework#48)
- [49: Add tests for exceptions and improve some messages](zendframework#49)
- [50: Optional fields without value should be valid ](zendframework#50)
- [51: Optional input without value are valid](zendframework#51)
- [52: Fix merge two inputs without value, result 'has value' flag should be false](zendframework#52)
- [56: Hotfix/minor changes](zendframework#56)
- [57: Consolidate tests for InputFilterInterface](zendframework#57)
- [61: Provide NotEmpty::IS&zendframework#95;EMPTY validation message for required input](zendframework#61)
- [63: Ensure custom error messages are used for required missing inputs](zendframework#63)
- [64: Feature/test cleanup](zendframework#64)
weierophinney added a commit to weierophinney/zend-inputfilter that referenced this issue Sep 9, 2015
Includes these changes:

- [14: NotEmpty validator doesn't override the required attribute](zendframework#14)
- [16: BC in validators context value](zendframework#16)
- [24: Fix loop validation input context is mutable](zendframework#24)
- [25: Fix missing optional fields should not be validated](zendframework#25)
- [26: Deprecate magic logic for auto attaching a NonEmpty validator with breakChainOnFailure = true](zendframework#26)
- [31: Update the InputFilterInterface::add docblock to match existing, shipped implementations](zendframework#31)
- [36: Fix docblocks declared as regular comment block](zendframework#36)
- [40: Remove test about Input setters permutation](zendframework#40)
- [41: Refactor tests for group 7448 as a data set matrix](zendframework#41)
- [42: Consolidate InputFilterPluginManager tests](zendframework#42)
- [43: Consolidate Factory tests + Fixes](zendframework#43)
- [44: Consolidate of InputInterface::merge and Fix unsafe merge](zendframework#44)
- [45: When merge Inputs don't merge values if source does not have one.](zendframework#45)
- [46: Expand test matrix with nonempty value scenarios](zendframework#46)
- [47: Feature/minor test improvements](zendframework#47)
- [48: Empty values + Allow Empty + Not continue if empty is always true](zendframework#48)
- [49: Add tests for exceptions and improve some messages](zendframework#49)
- [50: Optional fields without value should be valid ](zendframework#50)
- [51: Optional input without value are valid](zendframework#51)
- [52: Fix merge two inputs without value, result 'has value' flag should be false](zendframework#52)
- [56: Hotfix/minor changes](zendframework#56)
- [57: Consolidate tests for InputFilterInterface](zendframework#57)
- [61: Provide NotEmpty::IS&zendframework#95;EMPTY validation message for required input](zendframework#61)
- [63: Ensure custom error messages are used for required missing inputs](zendframework#63)
- [64: Feature/test cleanup](zendframework#64)
weierophinney added a commit to weierophinney/zend-inputfilter that referenced this issue Sep 9, 2015
Includes these changes:

- [14: NotEmpty validator doesn't override the required attribute](zendframework#14)
- [16: BC in validators context value](zendframework#16)
- [24: Fix loop validation input context is mutable](zendframework#24)
- [25: Fix missing optional fields should not be validated](zendframework#25)
- [26: Deprecate magic logic for auto attaching a NonEmpty validator with breakChainOnFailure = true](zendframework#26)
- [31: Update the InputFilterInterface::add docblock to match existing, shipped implementations](zendframework#31)
- [36: Fix docblocks declared as regular comment block](zendframework#36)
- [40: Remove test about Input setters permutation](zendframework#40)
- [41: Refactor tests for group 7448 as a data set matrix](zendframework#41)
- [42: Consolidate InputFilterPluginManager tests](zendframework#42)
- [43: Consolidate Factory tests + Fixes](zendframework#43)
- [44: Consolidate of InputInterface::merge and Fix unsafe merge](zendframework#44)
- [45: When merge Inputs don't merge values if source does not have one.](zendframework#45)
- [46: Expand test matrix with nonempty value scenarios](zendframework#46)
- [47: Feature/minor test improvements](zendframework#47)
- [48: Empty values + Allow Empty + Not continue if empty is always true](zendframework#48)
- [49: Add tests for exceptions and improve some messages](zendframework#49)
- [50: Optional fields without value should be valid ](zendframework#50)
- [51: Optional input without value are valid](zendframework#51)
- [52: Fix merge two inputs without value, result 'has value' flag should be false](zendframework#52)
- [56: Hotfix/minor changes](zendframework#56)
- [57: Consolidate tests for InputFilterInterface](zendframework#57)
- [61: Provide NotEmpty::IS&zendframework#95;EMPTY validation message for required input](zendframework#61)
- [63: Ensure custom error messages are used for required missing inputs](zendframework#63)
- [64: Feature/test cleanup](zendframework#64)
weierophinney added a commit to zendframework/zendframework that referenced this issue Dec 20, 2016
Includes these changes:

- [14: NotEmpty validator doesn't override the required attribute](zendframework/zend-inputfilter#14)
- [16: BC in validators context value](zendframework/zend-inputfilter#16)
- [24: Fix loop validation input context is mutable](zendframework/zend-inputfilter#24)
- [25: Fix missing optional fields should not be validated](zendframework/zend-inputfilter#25)
- [26: Deprecate magic logic for auto attaching a NonEmpty validator with breakChainOnFailure = true](zendframework/zend-inputfilter#26)
- [31: Update the InputFilterInterface::add docblock to match existing, shipped implementations](zendframework/zend-inputfilter#31)
- [36: Fix docblocks declared as regular comment block](zendframework/zend-inputfilter#36)
- [40: Remove test about Input setters permutation](zendframework/zend-inputfilter#40)
- [41: Refactor tests for group 7448 as a data set matrix](zendframework/zend-inputfilter#41)
- [42: Consolidate InputFilterPluginManager tests](zendframework/zend-inputfilter#42)
- [43: Consolidate Factory tests + Fixes](zendframework/zend-inputfilter#43)
- [44: Consolidate of InputInterface::merge and Fix unsafe merge](zendframework/zend-inputfilter#44)
- [45: When merge Inputs don't merge values if source does not have one.](zendframework/zend-inputfilter#45)
- [46: Expand test matrix with nonempty value scenarios](zendframework/zend-inputfilter#46)
- [47: Feature/minor test improvements](zendframework/zend-inputfilter#47)
- [48: Empty values + Allow Empty + Not continue if empty is always true](zendframework/zend-inputfilter#48)
- [49: Add tests for exceptions and improve some messages](zendframework/zend-inputfilter#49)
- [50: Optional fields without value should be valid ](zendframework/zend-inputfilter#50)
- [51: Optional input without value are valid](zendframework/zend-inputfilter#51)
- [52: Fix merge two inputs without value, result 'has value' flag should be false](zendframework/zend-inputfilter#52)
- [56: Hotfix/minor changes](zendframework/zend-inputfilter#56)
- [57: Consolidate tests for InputFilterInterface](zendframework/zend-inputfilter#57)
- [61: Provide NotEmpty::IS&#95;EMPTY validation message for required input](zendframework/zend-inputfilter#61)
- [63: Ensure custom error messages are used for required missing inputs](zendframework/zend-inputfilter#63)
- [64: Feature/test cleanup](zendframework/zend-inputfilter#64)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants