[wp-trac] [WordPress Trac] #43977: Fix error-prone string to array parsing
WordPress Trac
noreply at wordpress.org
Tue Aug 28 14:30:39 UTC 2018
#43977: Fix error-prone string to array parsing
----------------------------------------+-----------------------
Reporter: flixos90 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: 5.0
Component: General | Version:
Severity: normal | Resolution:
Keywords: needs-unit-tests has-patch | Focuses: rest-api
----------------------------------------+-----------------------
Changes (by flixos90):
* keywords: needs-unit-tests => needs-unit-tests has-patch
Comment:
Thanks for the work on this @sstoqnov!
[attachment:"43977.2.diff"] is an update that outsources the relevant code
into a new function: `wp_parse_list()` is similar to the existing
`wp_parse_id_list()` and `wp_parse_slug_list()`, however without applying
any additional sanitization on the list items.
The function contains the fix for `preg_split()` using the
`PREG_SPLIT_NO_EMPTY` flag (good idea @sstoqnov!). There is one case where
that flag doesn't really work though: If an empty string is passed to the
function, the result will still be an array with one empty string in it,
which is not what we want, so we need to work around it with an extra
check.
`wp_parse_id_list()` and `wp_parse_slug_list()` now internally call
`wp_parse_list()`.
All code using `preg_split()` in such a way was adjusted to either use
`wp_parse_list()`, `wp_parse_id_list()` or `wp_parse_slug_list()`,
according to what type the respective content is expected to have. The
surrounding `! is_array()` calls were also removed because the function
already takes care of that.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/43977#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list