Ticket #43977: 43977.3.diff
File 43977.3.diff, 14.9 KB (added by , 6 years ago) |
---|
-
src/wp-includes/bookmark.php
diff --git a/src/wp-includes/bookmark.php b/src/wp-includes/bookmark.php index b0de276..3249954 100644
a b function get_bookmarks( $args = '' ) { 171 171 $r['exclude'] = ''; //ignore exclude, category, and category_name params if using include 172 172 $r['category'] = ''; 173 173 $r['category_name'] = ''; 174 $inclinks = preg_split( '/[\s,]+/',$r['include'] );174 $inclinks = wp_parse_id_list( $r['include'] ); 175 175 if ( count( $inclinks ) ) { 176 176 foreach ( $inclinks as $inclink ) { 177 177 if ( empty( $inclusions ) ) { 178 $inclusions = ' AND ( link_id = ' . intval( $inclink ). ' ';178 $inclusions = ' AND ( link_id = ' . $inclink . ' '; 179 179 } else { 180 $inclusions .= ' OR link_id = ' . intval( $inclink ). ' ';180 $inclusions .= ' OR link_id = ' . $inclink . ' '; 181 181 } 182 182 } 183 183 } … … function get_bookmarks( $args = '' ) { 188 188 189 189 $exclusions = ''; 190 190 if ( ! empty( $r['exclude'] ) ) { 191 $exlinks = preg_split( '/[\s,]+/',$r['exclude'] );191 $exlinks = wp_parse_id_list( $r['exclude'] ); 192 192 if ( count( $exlinks ) ) { 193 193 foreach ( $exlinks as $exlink ) { 194 194 if ( empty( $exclusions ) ) { 195 $exclusions = ' AND ( link_id <> ' . intval( $exlink ). ' ';195 $exclusions = ' AND ( link_id <> ' . $exlink . ' '; 196 196 } else { 197 $exclusions .= ' AND link_id <> ' . intval( $exlink ). ' ';197 $exclusions .= ' AND link_id <> ' . $exlink . ' '; 198 198 } 199 199 } 200 200 } … … function get_bookmarks( $args = '' ) { 223 223 $category_query = ''; 224 224 $join = ''; 225 225 if ( ! empty( $r['category'] ) ) { 226 $incategories = preg_split( '/[\s,]+/',$r['category'] );226 $incategories = wp_parse_id_list( $r['category'] ); 227 227 if ( count( $incategories ) ) { 228 228 foreach ( $incategories as $incat ) { 229 229 if ( empty( $category_query ) ) { 230 $category_query = ' AND ( tt.term_id = ' . intval( $incat ). ' ';230 $category_query = ' AND ( tt.term_id = ' . $incat . ' '; 231 231 } else { 232 $category_query .= ' OR tt.term_id = ' . intval( $incat ). ' ';232 $category_query .= ' OR tt.term_id = ' . $incat . ' '; 233 233 } 234 234 } 235 235 } -
src/wp-includes/class-wp-comment-query.php
diff --git a/src/wp-includes/class-wp-comment-query.php b/src/wp-includes/class-wp-comment-query.php index d0e7cff..1f58c58 100644
a b class WP_Comment_Query { 482 482 483 483 // 'status' accepts an array or a comma-separated string. 484 484 $status_clauses = array(); 485 $statuses = $this->query_vars['status']; 486 if ( ! is_array( $statuses ) ) { 487 $statuses = preg_split( '/[\s,]+/', $statuses ); 485 $statuses = wp_parse_list( $this->query_vars['status'] ); 486 487 // Empty 'status' should be interpreted as 'all'. 488 if ( empty( $statuses ) ) { 489 $statuses = array( 'all' ); 488 490 } 489 491 490 492 // 'any' overrides other statuses. … … class WP_Comment_Query { 517 519 518 520 // User IDs or emails whose unapproved comments are included, regardless of $status. 519 521 if ( ! empty( $this->query_vars['include_unapproved'] ) ) { 520 $include_unapproved = $this->query_vars['include_unapproved']; 521 522 // Accepts arrays or comma-separated strings. 523 if ( ! is_array( $include_unapproved ) ) { 524 $include_unapproved = preg_split( '/[\s,]+/', $include_unapproved ); 525 } 522 $include_unapproved = wp_parse_list( $this->query_vars['include_unapproved'] ); 526 523 527 $unapproved_ids = $unapproved_emails = array(); 524 $unapproved_ids = array(); 525 $unapproved_emails = array(); 528 526 foreach ( $include_unapproved as $unapproved_identifier ) { 529 527 // Numeric values are assumed to be user ids. 530 528 if ( is_numeric( $unapproved_identifier ) ) { -
src/wp-includes/functions.php
diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index f307031..1d37930 100644
a b function wp_parse_args( $args, $defaults = '' ) { 3748 3748 } 3749 3749 3750 3750 /** 3751 * Cleans up an array, comma- or space-separated list of scalar values. 3752 * 3753 * @since 5.0.0 3754 * 3755 * @param array|string $list List of values. 3756 * @return array Sanitized array of values. 3757 */ 3758 function wp_parse_list( $list ) { 3759 if ( ! is_array( $list ) ) { 3760 return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); 3761 } 3762 3763 return $list; 3764 } 3765 3766 /** 3751 3767 * Clean up an array, comma- or space-separated list of IDs. 3752 3768 * 3753 3769 * @since 3.0.0 … … function wp_parse_args( $args, $defaults = '' ) { 3756 3772 * @return array Sanitized array of IDs. 3757 3773 */ 3758 3774 function wp_parse_id_list( $list ) { 3759 if ( ! is_array( $list ) ) { 3760 $list = preg_split( '/[\s,]+/', $list ); 3761 } 3775 $list = wp_parse_list( $list ); 3762 3776 3763 3777 return array_unique( array_map( 'absint', $list ) ); 3764 3778 } … … function wp_parse_id_list( $list ) { 3772 3786 * @return array Sanitized array of slugs. 3773 3787 */ 3774 3788 function wp_parse_slug_list( $list ) { 3775 if ( ! is_array( $list ) ) { 3776 $list = preg_split( '/[\s,]+/', $list ); 3777 } 3778 3779 foreach ( $list as $key => $value ) { 3780 $list[ $key ] = sanitize_title( $value ); 3781 } 3789 $list = wp_parse_list( $list ); 3782 3790 3783 return array_unique( $list);3791 return array_unique( array_map( 'sanitize_title', $list ) ); 3784 3792 } 3785 3793 3786 3794 /** -
src/wp-includes/post.php
diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 7feb284..e220ee9 100644
a b function get_pages( $args = array() ) { 5004 5004 5005 5005 $author_query = ''; 5006 5006 if ( ! empty( $r['authors'] ) ) { 5007 $post_authors = preg_split( '/[\s,]+/',$r['authors'] );5007 $post_authors = wp_parse_list( $r['authors'] ); 5008 5008 5009 5009 if ( ! empty( $post_authors ) ) { 5010 5010 foreach ( $post_authors as $post_author ) { -
src/wp-includes/rest-api.php
diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index 0cce9fa..0feb681 100644
a b function rest_filter_response_fields( $response, $server, $request ) { 651 651 652 652 $data = $response->get_data(); 653 653 654 $fields = is_array( $request['_fields'] ) ? $request['_fields'] : preg_split( '/[\s,]+/',$request['_fields'] );654 $fields = wp_parse_list( $request['_fields'] ); 655 655 656 656 if ( 0 === count( $fields ) ) { 657 657 return $response; … … function rest_get_avatar_sizes() { 1081 1081 */ 1082 1082 function rest_validate_value_from_schema( $value, $args, $param = '' ) { 1083 1083 if ( 'array' === $args['type'] ) { 1084 if ( ! is_array( $value ) ) { 1085 $value = preg_split( '/[\s,]+/', $value ); 1086 } 1084 $value = wp_parse_list( $value ); 1087 1085 if ( ! wp_is_numeric_array( $value ) ) { 1088 1086 /* translators: 1: parameter, 2: type name */ 1089 1087 return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s.' ), $param, 'array' ) ); … … function rest_sanitize_value_from_schema( $value, $args ) { 1225 1223 if ( empty( $args['items'] ) ) { 1226 1224 return (array) $value; 1227 1225 } 1228 if ( ! is_array( $value ) ) { 1229 $value = preg_split( '/[\s,]+/', $value ); 1230 } 1226 $value = wp_parse_list( $value ); 1231 1227 foreach ( $value as $index => $v ) { 1232 1228 $value[ $index ] = rest_sanitize_value_from_schema( $v, $args['items'] ); 1233 1229 } -
src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php
diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php index 1b73881..4c2c187 100644
a b abstract class WP_REST_Controller { 521 521 if ( ! isset( $request['_fields'] ) ) { 522 522 return $fields; 523 523 } 524 $requested_fields = is_array( $request['_fields'] ) ? $request['_fields'] : preg_split( '/[\s,]+/',$request['_fields'] );524 $requested_fields = wp_parse_list( $request['_fields'] ); 525 525 if ( 0 === count( $requested_fields ) ) { 526 526 return $fields; 527 527 } -
tests/phpunit/tests/bookmark/getBookmarks.php
diff --git a/tests/phpunit/tests/bookmark/getBookmarks.php b/tests/phpunit/tests/bookmark/getBookmarks.php index 13f8795..c605a9f 100644
a b class Tests_Bookmark_GetBookmarks extends WP_UnitTestCase { 84 84 $this->assertEqualSets( $found1, $found2 ); 85 85 $this->assertTrue( $num_queries < $wpdb->num_queries ); 86 86 } 87 88 public function test_exclude_param_gets_properly_parsed_as_list() { 89 $bookmarks = self::factory()->bookmark->create_many( 3 ); 90 91 $found = get_bookmarks( 92 array( 93 'exclude' => ',,', 94 ) 95 ); 96 $found_ids = array(); 97 foreach( $found as $bookmark ) { 98 $found_ids[] = $bookmark->link_id; 99 } 100 101 // equal sets != same order. 102 $this->assertEqualSets( $bookmarks, $found_ids ); 103 } 104 105 public function test_include_param_gets_properly_parsed_as_list() { 106 $bookmarks = self::factory()->bookmark->create_many( 3 ); 107 108 $found = get_bookmarks( 109 array( 110 'include' => ',,', 111 ) 112 ); 113 $found_ids = array(); 114 foreach( $found as $bookmark ) { 115 $found_ids[] = $bookmark->link_id; 116 } 117 118 // equal sets != same order. 119 $this->assertEqualSets( $bookmarks, $found_ids ); 120 } 121 122 public function test_category_param_propelry_gets_parsed_as_list() { 123 $bookmarks = self::factory()->bookmark->create_many( 3 ); 124 $categories = self::factory()->term->create_many( 3, array( 125 'taxonomy' => 'link_category', 126 ) ); 127 $add = wp_add_object_terms( $bookmarks[0], $categories[0], 'link_category' ); 128 $add = wp_add_object_terms( $bookmarks[1], $categories[1], 'link_category' ); 129 $add = wp_add_object_terms( $bookmarks[2], $categories[2], 'link_category' ); 130 131 $found = get_bookmarks( 132 array( 133 'category' => ',,', 134 ) 135 ); 136 $found_ids = array(); 137 foreach( $found as $bookmark ) { 138 $found_ids[] = $bookmark->link_id; 139 } 140 141 // equal sets != same order. 142 $this->assertEqualSets( $bookmarks, $found_ids ); 143 } 87 144 } -
tests/phpunit/tests/functions.php
diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index 2557f1f..a3491c8 100644
a b class Tests_Functions extends WP_UnitTestCase { 573 573 } 574 574 575 575 /** 576 * @dataProvider data_wp_parse_list 577 */ 578 function test_wp_parse_list( $expected, $actual ) { 579 $this->assertSame( $expected, array_values( wp_parse_list( $actual ) ) ); 580 } 581 582 function data_wp_parse_list() { 583 return array( 584 array( array( '1', '2', '3', '4' ), '1,2,3,4' ), 585 array( array( 'apple', 'banana', 'carrot', 'dog' ), 'apple,banana,carrot,dog' ), 586 array( array( '1', '2', 'apple', 'banana' ), '1,2,apple,banana' ), 587 array( array( '1', '2', 'apple', 'banana' ), '1, 2,apple,banana' ), 588 array( array( '1', '2', 'apple', 'banana' ), '1,2,apple,,banana' ), 589 array( array( '1', '2', 'apple', 'banana' ), ',1,2,apple,banana' ), 590 array( array( '1', '2', 'apple', 'banana' ), '1,2,apple,banana,' ), 591 array( array( '1', '2', 'apple', 'banana' ), '1,2 ,apple,banana' ), 592 array( array(), '' ), 593 array( array(), ',' ), 594 array( array(), ',,' ), 595 ); 596 } 597 598 /** 576 599 * @dataProvider data_wp_parse_id_list 577 600 */ 578 601 function test_wp_parse_id_list( $expected, $actual ) { -
tests/phpunit/tests/rest-api/rest-controller.php
diff --git a/tests/phpunit/tests/rest-api/rest-controller.php b/tests/phpunit/tests/rest-api/rest-controller.php index 809ec17..02e6622 100644
a b class WP_Test_REST_Controller extends WP_Test_REST_TestCase { 203 203 $this->assertEquals( 'a', $args['somedefault']['default'] ); 204 204 } 205 205 206 public function test_get_fields_for_response() { 206 /** 207 * @dataProvider data_get_fields_for_response, 208 */ 209 public function test_get_fields_for_response( $param, $expected ) { 207 210 $controller = new WP_REST_Test_Controller(); 208 211 $request = new WP_REST_Request( 'GET', '/wp/v2/testroute' ); 209 212 $fields = $controller->get_fields_for_response( $request ); … … class WP_Test_REST_Controller extends WP_Test_REST_TestCase { 221 224 ), 222 225 $fields 223 226 ); 224 $request->set_param( '_fields', 'somestring,someinteger');227 $request->set_param( '_fields', $param ); 225 228 $fields = $controller->get_fields_for_response( $request ); 226 $this->assertEquals( 229 $this->assertEquals( $expected, $fields ); 230 } 231 232 public function data_get_fields_for_response() { 233 return array( 227 234 array( 228 'somestring', 229 'someinteger', 235 'somestring,someinteger', 236 array( 237 'somestring', 238 'someinteger', 239 ), 240 ), 241 array( 242 ',,', 243 array( 244 'somestring', 245 'someinteger', 246 'someboolean', 247 'someurl', 248 'somedate', 249 'someemail', 250 'someenum', 251 'someargoptions', 252 'somedefault', 253 ), 230 254 ), 231 $fields232 255 ); 233 256 } 234 257 } -
tests/phpunit/tests/rest-api/rest-schema-sanitization.php
diff --git a/tests/phpunit/tests/rest-api/rest-schema-sanitization.php b/tests/phpunit/tests/rest-api/rest-schema-sanitization.php index b3a3a49..6dc0864 100644
a b class WP_Test_REST_Schema_Sanitization extends WP_UnitTestCase { 110 110 ); 111 111 $this->assertEquals( array( 1, 2 ), rest_sanitize_value_from_schema( '1,2', $schema ) ); 112 112 $this->assertEquals( array( 1, 2, 0 ), rest_sanitize_value_from_schema( '1,2,a', $schema ) ); 113 $this->assertEquals( array( 1, 2 ), rest_sanitize_value_from_schema( '1,2,', $schema ) ); 113 114 } 114 115 115 116 public function test_type_array_with_enum() { … … class WP_Test_REST_Schema_Sanitization extends WP_UnitTestCase { 134 135 ); 135 136 $this->assertEquals( array( 'ribs', 'chicken' ), rest_sanitize_value_from_schema( 'ribs,chicken', $schema ) ); 136 137 $this->assertEquals( array( 'chicken', 'coleslaw' ), rest_sanitize_value_from_schema( 'chicken,coleslaw', $schema ) ); 138 $this->assertEquals( array( 'chicken', 'coleslaw' ), rest_sanitize_value_from_schema( 'chicken,coleslaw,', $schema ) ); 137 139 } 138 140 139 141 public function test_type_array_is_associative() { -
tests/phpunit/tests/rest-api/rest-schema-validation.php
diff --git a/tests/phpunit/tests/rest-api/rest-schema-validation.php b/tests/phpunit/tests/rest-api/rest-schema-validation.php index 5cd3177..81c71d2 100644
a b class WP_Test_REST_Schema_Validation extends WP_UnitTestCase { 145 145 $this->assertTrue( rest_validate_value_from_schema( '1', $schema ) ); 146 146 $this->assertTrue( rest_validate_value_from_schema( '1,2,3', $schema ) ); 147 147 $this->assertWPError( rest_validate_value_from_schema( 'lol', $schema ) ); 148 $this->assertTrue( rest_validate_value_from_schema( '1,,', $schema ) ); 149 $this->assertTrue( rest_validate_value_from_schema( '', $schema ) ); 148 150 } 149 151 150 152 public function test_type_array_with_enum() { … … class WP_Test_REST_Schema_Validation extends WP_UnitTestCase { 169 171 ); 170 172 $this->assertTrue( rest_validate_value_from_schema( 'ribs,chicken', $schema ) ); 171 173 $this->assertWPError( rest_validate_value_from_schema( 'chicken,coleslaw', $schema ) ); 174 $this->assertTrue( rest_validate_value_from_schema( 'ribs,chicken,', $schema ) ); 175 $this->assertTrue( rest_validate_value_from_schema( '', $schema ) ); 172 176 } 173 177 174 178 public function test_type_array_is_associative() {