-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Conversation
- To retain BC, filters should never raise exceptions - Instead, raising warning and returning original value
- null values should be filtered without warnings
- null values should not be filtered, and should not raise warnings
If we accept an agreement that any Filter instance of Zend\Filter\FilterInterface should generate an error if it can not filter out, it is best to leave the exception. I want to draw attention to such cases: Lets we have $input (instance of InputFilrer\Input) based on config below
and we have any $data (of course not valid).
then i call $input->isValid() will be triggered notice. If this data is from form it's logical trigger notice to developer to show that form does not correspond to inputFilter. But this data may be from any part, for example from GET.
|
@gag237 It's a bad idea to use try/catch for logical branching -- if nothing else, because it adds a ton of processing overhead. Additionally, you're confusing filtering and validation. In the InputFilter, filters happen prior to validation -- so even if the values cannot be filtered, they will likely still fail validation. Throwing the notice is still useful in these situations, however, as you can then see in the logs that some location on your site is submitting data incorrectly -- or somebody is attempting to trigger failures to try and find vulnerabilities. |
Perhaps you are right. Is it possible to change the description of Filter\FilterInterfatse::filter() when the filter should throw an exception RuntimeException, when trigger error. |
@gag237 Go for it. |
That methods have a contract for return If this try to resolve a BC Break I suggest revert the original PR (#4734) and apply it for the next "major" version |
@Maks3w It's not a BC break; it's correcting already released behavior to be more consistent and less brittle. |
Can you update the docblocks for reflect the changes? (return types and some note about the E_USER_WARNING) |
- Added a paragraph indicating inability to filter non-scalar values, and that a warning will be raised in such circumstances. - Updated return annotations to indicate a "mixed" possibility.
@Maks3w Done. |
- To retain BC, filters should never raise exceptions - Instead, raising warning and returning original value
- null values should be filtered without warnings
- null values should not be filtered, and should not raise warnings
#4734 introduced some type checking into a number of filters in order to remove notices that were being raised about "array to string" conversions. However, it did so by raising exceptions, which will be a non-starter for anybody who was previously passing arrays and/or objects to these filters.
Likely the more appropriate method would be to simply return the value presented, and potentially raise an
E_USER_WARNING
indicating the filter's inability to process the value.