Fix all known issues + inconsistencies #12
Closed
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.
What kind of change does this PR introduce? (pls check at least one)
Description
This update makes a few changes that require a new major version in order to not mess up the flow of existing applications. We however believe that the changes are necessary. They are all detailed below:
Changes to the way arrays are validated. The previous version had an
array()
rule which was considered a "special rule" different from the way all other rules were validated. This had some problems like performance issues and also errors when using complex validators likemin:x
together witharray()
. There were also issues when combining multiple validators together with array() eg:array(string|numeric)
which would accept['123']
but this failed.array()
is replaced by thearray
rule in this version which is a real rule but can also be extended to validate items in an array likearray<numeric|string>
. Unlike the previous version, this also works with complex validators:array<string|min:3|between:[2,5]>
Fixed inconsistencies in validation. Internally, there were some issues that led to validators being inefficient and/or insecure (of course, other parts of Leaf covered up the vulnerabilities). This version removes all those weak links and makes validation more consistent between functions
Fixed breaks when chaining complex validators as strings. There was an issue where chaining complex validators like
min:x
andcontains:x
as strings could break the validation flow, this was also the case with array and |. Basically, all those issues have been fixed now.Every item that should be validated is required by default. Before we had the opposite flow where every item was optional by default, so you needed to add
required
. This was quite clumsy because more often than not, people validate required fields. This update corrects that behaviour and offers anoptional
rule for fields that can be empty or nullable.Additional petty fixes have been made to validators that did not work as expected in the previous version. An example is the
in
validator which just did not work right depending on the condition. This and other validators have been fixed in this version.The release will be tagged as v3 since it breaks a lot of flows from the previous version, especially the default required change.
Does this PR introduce a breaking change? (check one)
Related Issue
#11