[wp-trac] [WordPress Trac] #42961: Rest API doesnt handle empty arrays in querystring correctly
WordPress Trac
noreply at wordpress.org
Fri Dec 22 03:41:22 UTC 2017
#42961: Rest API doesnt handle empty arrays in querystring correctly
--------------------------+------------------------------
Reporter: steffanhalv | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version: 4.7
Severity: normal | Resolution:
Keywords: | Focuses: rest-api
--------------------------+------------------------------
Changes (by dd32):
* version: 4.9.1 => 4.7
Comment:
This appears to be the correct behaviour, although an unexpected one at
that.
> Ex. Querystring:
> mysite.com/wp-json/...?my_empty_array[]=&... <- This works not
In PHP applications, `var[]=` is always treated as being set to an empty
string, that means that this is interpreted as `array( '' )`.
> JSON:
> data: { my_empty_array: [] } <- This works
When using JSON, you can pass more specific types than what you can in a
PHP Query string, which results in this being a literal `array()`
----
All that being said, this feels a little awkward, and I'd prefer to see it
standardised on the JSON behaviour, but I'm not sure it's really possible
though.
One option would be to run `array_filter()` on any array items in the
query string, but doing so also means moving away from standard PHP URL
parsing quirks.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/42961#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list