Repository navigation
Conversation
| } | ||
|
|
||
| if ( 'array' === $args['type'] ) { | ||
| // A comma-separated array of IDs could be acceptable instead of an array. |
There was a problem hiding this comment.
This isn't the right abstraction.
JSON Schema permits us to specify two different types for a given property. In the case of anything using wp_parse_id_list(), we need to specify type => [ 'string', 'array' ], and then properly validate an array of types.
There was a problem hiding this comment.
JSON Schema permits us to specify two different types for a given property. In the case of anything using
wp_parse_id_list(), we need to specifytype => [ 'string', 'array' ], and then properly validate an array of types.
I just want to make sure I'm understanding you correctly. In the case of type => [ 'string', 'array' ], we should ideally be checking for an array, and then ensuring that each element is a string? Or as another example, type => [ 'integer', 'array' ] would mean checking for an array of integers?
There was a problem hiding this comment.
In JSON Schema, I believe the way to define an arrays type is like so
"options": {
"type": "array",
"minItems": 1,
"items": { "type": "string" },
"uniqueItems": true
},|
@JPry: @BE-Webdesign had already started a PR for this issue in #2361. Which of you wants to take this all of the way through? |
|
Doesn't matter to me, I'm happy to refine my PR or have somebody do a much better one 😃! |
|
I don't mind if @BE-Webdesign's PR goes forward instead of mine. I just happened to have a couple of hours available and wanted to help out, so I picked a couple of issues in the Beta 13 milestone. |
|
I do have an hour or 2 this morning to work on this, so maybe I'll see how far I can get 😄 |
|
@JPry is there any update that needs to be added here, or is this changed direction and needs to be closed out? |
|
@joehoyle Give me a day or two to review this, and then we can close it out if nothing has changed. |
* develop: (200 commits)
Fix extra space
Fix code standards issues from our PHPCS rules
Revert "Fixed styling issues. Maybe."
Properly register "{taxonomy}_exclude" parameters in the schema
Fixed styling issues. Maybe.
Fix error when a single meta value attempts to update to the current value. Adds test.
Correct @see url for WP_Query
Revert 6e1f9ba
Remove conditional check on the `unfiltered_html` cap for discussion
Remove temporary fix for upstream bug 35614.
Documentation and code standards for `WP_REST_Terms_Controller`.
Update changelog with changes since beta14
Bump plugin version to 2.0beta15.
Test theory that the problem is caused by and admin updating a comment as a different user
Add back string type checking to content values
Pass current filter into wp_kses
Switch to `wp_filter_kses()` in an attempt to avoid having to pass global allowed tags
Handle multiple duplicate values correctly
Correct sanitization kses functions and re-add failing update content test
I hate PHP 5.3 and lower
...
|
I made some updates here based on this comment. If we're following the JSON schema as @joehoyle mentioned, then the changes I've made seem to be the right way forward. At this point I'm looking for some feedback on the approach I'm using. If what I've done here isn't the right way to go about this, then I would appreciate some input about what a better method might be. I'm also curious about the failed tests from when I merged |
|
@JPry thanks for expanding on this, so I think this works, however i think it could be more elegant. If we have a function I have an idea of how this could work, I'm happy to adapt this to try that direction. |
|
Thanks for the idea @joehoyle. I'd be willing to make some updates to this based on your idea and what @BE-Webdesign mentioned in slack today. For my own reference, here are the relevant links from slack: https://wordpress.slack.com/archives/core-restapi/p1476455590007085 |
| // Map values to the correct type, defaulting to string as the type. | ||
| $type = isset( $args['items']['type'] ) ? $args['items']['type'] : 'string'; | ||
| foreach ( $value as &$_value ) { | ||
| settype( $_value, $type ); |
There was a problem hiding this comment.
Rather than using settype we should use our own validation systems because settype can lead to the wrong information. We can get away with settype though as most of the endpoints only deal with arrays of strings or integers. If this PR plans to handle booleans then this will cause a problem when values like 'false' are passed into an array booleans.
| 'somecsv' => array( | ||
| 'type' => 'array', | ||
| 'allow_csv' => true, | ||
| ), |
There was a problem hiding this comment.
We need to test against the actual JSON Schema here. So we need to have items added. In a PR I did that I ultimately did not like I had schema like this.
someIdList => array(
'type' => 'array',
'items' => array(
'type' => 'integer'
),
'minItems' => 1,
'uniqueItems' => true,
),Then the same thing for string lists. Currently in the endpoints most of the arrays are id lists and only a few are string lists.
| case 'boolean': | ||
| $function = 'rest_is_boolean'; | ||
| break; | ||
|
|
There was a problem hiding this comment.
I wouldn't worry about supporting boolean because there are no endpoint parameters that use an array of booleans. This PR won't handle booleans 100% properly so let's not check for them.
| case 'string': | ||
| $function = 'is_string'; | ||
| break; | ||
| } |
There was a problem hiding this comment.
This should have a default case so there is no fall through, currently in the API we use super loose validation and most things will pass for true by default. I believe this PR is returning false for all of these values, that fall through.
| 'default' => array(), | ||
| 'sanitize_callback' => 'wp_parse_id_list', | ||
| 'validate_callback' => 'rest_validate_request_arg', | ||
| ); |
There was a problem hiding this comment.
The items schema needs to be added into all of the array parameters so that your validation is actually working. This is why all of the tests are failing because the schema is not set yet. Every include/exclude author_include/exclude parameter needs it and I believe user roles. There are some other ones that I can't remember.
Fixex #2194
This adds array validation to
rest_validate_request_arg()as described in #2194. Unit tests have been adeed for the new type.