@@ -227,6 +227,8 @@ public function test_get_items() {
227227
228228 /**
229229 * Test getting items of a specific status.
230+ *
231+ * @ticket 63982
230232 */
231233 public function test_get_items_by_status () {
232234 wp_set_current_user ( self ::$ admin_id );
@@ -253,6 +255,8 @@ public function test_get_items_by_status() {
253255
254256 /**
255257 * Test getting comments of all statuses.
258+ *
259+ * @ticket 63982
256260 */
257261 public function test_get_items_by_all_status () {
258262 wp_set_current_user ( self ::$ admin_id );
@@ -278,6 +282,8 @@ public function test_get_items_by_all_status() {
278282
279283 /**
280284 * Test getting items of multiple statuses.
285+ *
286+ * @ticket 63982
281287 */
282288 public function test_get_items_by_multiple_status () {
283289 wp_set_current_user ( self ::$ admin_id );
@@ -301,6 +307,69 @@ public function test_get_items_by_multiple_status() {
301307 $ this ->assertCount ( $ found , $ comments );
302308 }
303309
310+ /**
311+ * Test sanization of the status parameter.
312+ *
313+ * @ticket 63982
314+ *
315+ * @dataProvider data_get_items_by_status_sanitize
316+ */
317+ public function test_get_items_by_status_sanitize ( $ key , $ expected ) {
318+ wp_set_current_user ( self ::$ admin_id );
319+
320+ // Create a post with the test status.
321+ $ params = array (
322+ 'post ' => self ::$ post_id ,
323+ 'author_name ' => 'Comic Book Guy ' ,
324+ 'author_email ' =>
'[email protected] ' ,
325+ 'author_url ' => 'http://androidsdungeon.com ' ,
326+ 'content ' => 'Worst Comment Ever! ' ,
327+ 'status ' => $ key ,
328+ );
329+
330+ $ request = new WP_REST_Request ( 'POST ' , '/wp/v2/comments ' );
331+ $ request ->add_header ( 'Content-Type ' , 'application/json ' );
332+ $ request ->set_body ( wp_json_encode ( $ params ) );
333+
334+ $ response = rest_get_server ()->dispatch ( $ request );
335+ $ this ->assertSame ( 201 , $ response ->get_status () );
336+
337+ $ comment = $ response ->get_data ();
338+
339+ $ this ->assertEquals ( $ expected , $ comment ['status ' ] );
340+ }
341+
342+ /**
343+ * Data provider.
344+ *
345+ * @return array
346+ */
347+ public function data_get_items_by_status_sanitize () {
348+ return array (
349+ 'an empty string key ' => array (
350+ 'key ' => '' ,
351+ 'expected ' => 'hold ' ,
352+ ),
353+ 'a lowercase key with commas ' => array (
354+ 'key ' => 'howdy,admin ' ,
355+ 'expected ' => 'hold ' ,
356+ ),
357+ 'a lowercase key with commas ' => array (
358+ 'key ' => 'HOWDY,ADMIN ' ,
359+ 'expected ' => 'hold ' ,
360+ ),
361+ 'a mixed case key with commas ' => array (
362+ 'key ' => 'HoWdY,aDmIn ' ,
363+ 'expected ' => 'hold ' ,
364+ ),
365+ 'a string with unicode ' => array (
366+ 'key ' => array ( 'howdy admin ' , 'another-value ' ),
367+ 'expected ' => 'hold ' ,
368+ ),
369+ );
370+ }
371+
372+
304373 /**
305374 * @ticket 38692
306375 */
0 commit comments