[wp-trac] [WordPress Trac] #38531: Support for arrays in schema validation and sanitization
WordPress Trac
noreply at wordpress.org
Thu Oct 27 17:21:20 UTC 2016
#38531: Support for arrays in schema validation and sanitization
--------------------------+-----------------
Reporter: joehoyle | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: 4.7
Component: REST API | Version:
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------
Leading into https://github.com/WP-API/WP-API/issues/2859, the main thing
to solve here is sanitization / validation support for arrays. If you
specify `type => array` in endpoint args, then an additional `items =>
array( type => string )` is required to specify the schema for the items
in the array.
I've implemented a patch to support arrays (and easily objects in the
future) by abstracting our schema validation / sanitization a little to
supper them being called recursively, which means array validation is
quite simple.
Also, I added a good amount of tests for exactly what happens for each
type / format in validation.
There was a few leaks that I uncovered when doing this, such as Settings
allowing null values, and some places where we were specify `type =>
array` in endpoint args, but were not defined the `items` property. This
means we'll get a little better validation off the bat. A couple of other
fixes came along with this such as `numeric => number` typo for min / max
support, sanitization for `type => number` which we had previously missed.
I'd like to get some eyes on this from @rachebaker and @rmccue, this was a
little simpler than I had though, so I think we might be able to get this
in 4.7.
Once this is in, it will just be a case of allowing type => array to the
settings and meta endpoints. Also, this operates at the endpiont args
level, so `type => array` is also supported in collection params.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/38531>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list