[wp-trac] [WordPress Trac] #43977: Fix error-prone string to array parsing

WordPress Trac noreply at wordpress.org
Tue Oct 2 18:57:28 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

Comment (by david.binda):

 Running the existing unit tests shows that this change breaks the `status`
 param handling in  `WP_Comment_Query::get_comment_ids` covered by
 `Tests_Comment_Query ::test_status_empty_string` test.

 The handling of empty string passed to the `status` param was broken
 previously by changes introduced in [30084] and then hotfixed via [30093].

 However, the change also breaks another test, which I'm unsure how to get
 fixed, as I'm not sure whether the issue is with the test itself, or with
 the new code.

 is failing for the case when the option is non-existent. The current test
 expects `null` to be returned for a such setting, but the
 `WP_REST_Settings_Controller::get_item` function is casting schema's
 default `null` value to an array via
 `WP_REST_Settings_Controller::prepare_value` function. The current
 functionality, for not casting the `null` to an `array` is only possible
 due to the described "unexpected" behaviour of the `preg_split` call
 without `PREG_SPLIT_NO_EMPTY` flag set.

 I'm attaching an updated patch which fixes the broken empty `status` param
 handling and which adds unit tests covering the new function and extending
 existing unit tests for covering affected places in the code

Ticket URL: <https://core.trac.wordpress.org/ticket/43977#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list