[wp-trac] [WordPress Trac] #42961: Rest API doesnt handle empty arrays in querystring correctly
WordPress Trac
noreply at wordpress.org
Sat Nov 30 19:11:46 UTC 2019
#42961: Rest API doesnt handle empty arrays in querystring correctly
-------------------------------+-----------------------------------------
Reporter: steffanhalv | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version: 4.7
Severity: normal | Resolution:
Keywords: reporter-feedback | Focuses: rest-api, coding-standards
-------------------------------+-----------------------------------------
Comment (by steffanhalv):
@TimothyBlynJacobs I already did here
https://github.com/woocommerce/woocommerce/issues/18249.
But here is some other examples:
If you have a post with the id <id> it is not possible to delete the last
category or tag or role or any other 'last item of an array' using the
rest api with queryparams.
**This works (replacing or adding to an array ):**
{{{
POST /wp/v2/posts/<id>?categories[0]=...&categories[1]=...&...
POST /wp/v2/posts/<id>?tags[0]=...&...
POST /wp/v2/users/<id>?roles[0]=...&...
}}}
Response = success
**None of these works (trying to remove the last item of an array):**
{{{
POST /wp/v2/posts/<id>?categories[]=&...
POST /wp/v2/posts/<id>?tags=null&...
POST /wp/v2/users/<id>?roles[]=null&...
POST /wp/v2/users/<id>?roles[]=0&...
POST /wp/v2/users/<id>?roles=0&...
POST /wp/v2/users/<id>?roles=&...
POST /wc/v2/products?attributes[0]=...&...
}}}
Response =
{{{
code:"rest_invalid_param"
data:{status: 400, params: {attributes: "attributes[0] er ikke av typen
object."}}
message:"Ugyldig(e) parameter(e): attributes"
}}}
A post request to any of this endpoints has no possible ways to clear the
arrays using queryparams.
Yes, JSON works but JSON is not accepted in POST requests for many servers
as it has CORS restrictions which is not the case for queryparams. So the
conclusion is that empty arrays is not handled correctly by the WP core.
Also please notice that I have not URL Encoded the strings in this
example, but it is when Im doing the actual request.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/42961#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list