Repository navigation
[zend-form] reject array values for single value elements - #243
Open
falkenhawk wants to merge 2 commits into
Open
falkenhawk wants to merge 2 commits into
falkenhawk wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A tampered request like
name[]=xsends an array to a text field.Zend_Form_Element::isValid()passes the array on to the filters and validators:StringTrimturn the array into the text'Array', with a warning. That passesNotEmptyand any validator accepting this text, so the form is valid and the app saves'Array'.Zend_Filter_Callbackwithtrimor custom ones, throw aTypeErroron php 8value="Array"in the field, with a warningFix
A new
protected $_rejectArrayValueflag onZend_Form_Element, off by default.It is on for the built-in elements holding a single value:
Text,Textarea,Password,Hidden,Hash,SelectandRadio.Such an element, unless it is set up as an array element with
setIsArray(true), now drops an array value and fails validation with the errorinvalidType, "Invalid type given. String expected".The standard validators use the same message, so existing translations apply.
Custom messages set with
setErrorMessages()are used instead, as for validators.Backwards compatibility
Zend_Form_ElementandZend_Form_Element_Xhtmlstill accept arrays. Custom elements built from several inputs, which usually extendZend_Form_Element_Xhtmland take an array insetValue(), keep working.setValue(), so a subclass ofTextand the others that turns an array into a single value insetValue()keeps working toosetIsArray(true),MultiCheckbox,Multiselect),Captcha,File,Checkboxand the buttons are not affectedNot covered
Calling
populate()with an array and then rendering the form still showsvalue="Array"with a warning.That data comes from the app itself, it is not validated.
Ported from a private repository, based on work by @marcing. There, every element that is not an array element rejects arrays, which breaks custom elements built from several inputs.