Changeset 44546
- Timestamp:
- 01/10/2019 09:05:50 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/bookmark.php
r42343 r44546 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 } … … 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 } … … 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 } -
trunk/src/wp-includes/class-wp-comment-query.php
r44412 r44546 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 … … 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 } 526 527 $unapproved_ids = $unapproved_emails = array(); 522 $include_unapproved = wp_parse_list( $this->query_vars['include_unapproved'] ); 523 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. -
trunk/src/wp-includes/functions.php
r44506 r44546 3824 3824 3825 3825 /** 3826 * Cleans up an array, comma- or space-separated list of scalar values. 3827 * 3828 * @since 5.1.0 3829 * 3830 * @param array|string $list List of values. 3831 * @return array Sanitized array of values. 3832 */ 3833 function wp_parse_list( $list ) { 3834 if ( ! is_array( $list ) ) { 3835 return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); 3836 } 3837 3838 return $list; 3839 } 3840 3841 /** 3826 3842 * Clean up an array, comma- or space-separated list of IDs. 3827 3843 * … … 3832 3848 */ 3833 3849 function wp_parse_id_list( $list ) { 3834 if ( ! is_array( $list ) ) { 3835 $list = preg_split( '/[\s,]+/', $list ); 3836 } 3850 $list = wp_parse_list( $list ); 3837 3851 3838 3852 return array_unique( array_map( 'absint', $list ) ); … … 3848 3862 */ 3849 3863 function wp_parse_slug_list( $list ) { 3850 if ( ! is_array( $list ) ) { 3851 $list = preg_split( '/[\s,]+/', $list ); 3852 } 3853 3854 foreach ( $list as $key => $value ) { 3855 $list[ $key ] = sanitize_title( $value ); 3856 } 3857 3858 return array_unique( $list ); 3864 $list = wp_parse_list( $list ); 3865 3866 return array_unique( array_map( 'sanitize_title', $list ) ); 3859 3867 } 3860 3868 -
trunk/src/wp-includes/post.php
r44454 r44546 5089 5089 $author_query = ''; 5090 5090 if ( ! empty( $r['authors'] ) ) { 5091 $post_authors = preg_split( '/[\s,]+/',$r['authors'] );5091 $post_authors = wp_parse_list( $r['authors'] ); 5092 5092 5093 5093 if ( ! empty( $post_authors ) ) { -
trunk/src/wp-includes/rest-api.php
r44173 r44546 680 680 $data = $response->get_data(); 681 681 682 $fields = is_array( $request['_fields'] ) ? $request['_fields'] : preg_split( '/[\s,]+/',$request['_fields'] );682 $fields = wp_parse_list( $request['_fields'] ); 683 683 684 684 if ( 0 === count( $fields ) ) { … … 1110 1110 function rest_validate_value_from_schema( $value, $args, $param = '' ) { 1111 1111 if ( 'array' === $args['type'] ) { 1112 if ( ! is_ array( $value ) ) {1113 $value = preg_split( '/[\s,]+/',$value );1112 if ( ! is_null( $value ) ) { 1113 $value = wp_parse_list( $value ); 1114 1114 } 1115 1115 if ( ! wp_is_numeric_array( $value ) ) { … … 1254 1254 return (array) $value; 1255 1255 } 1256 if ( ! is_array( $value ) ) { 1257 $value = preg_split( '/[\s,]+/', $value ); 1258 } 1256 $value = wp_parse_list( $value ); 1259 1257 foreach ( $value as $index => $v ) { 1260 1258 $value[ $index ] = rest_sanitize_value_from_schema( $v, $args['items'] ); -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php
r44254 r44546 533 533 return $fields; 534 534 } 535 $requested_fields = is_array( $request['_fields'] ) ? $request['_fields'] : preg_split( '/[\s,]+/',$request['_fields'] );535 $requested_fields = wp_parse_list( $request['_fields'] ); 536 536 if ( 0 === count( $requested_fields ) ) { 537 537 return $fields; -
trunk/tests/phpunit/tests/bookmark/getBookmarks.php
r42343 r44546 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 } -
trunk/tests/phpunit/tests/functions.php
r44481 r44546 533 533 534 534 update_option( 'blog_charset', $orig_blog_charset ); 535 } 536 537 /** 538 * @ticket 43977 539 * @dataProvider data_wp_parse_list 540 */ 541 function test_wp_parse_list( $expected, $actual ) { 542 $this->assertSame( $expected, array_values( wp_parse_list( $actual ) ) ); 543 } 544 545 function data_wp_parse_list() { 546 return array( 547 array( array( '1', '2', '3', '4' ), '1,2,3,4' ), 548 array( array( 'apple', 'banana', 'carrot', 'dog' ), 'apple,banana,carrot,dog' ), 549 array( array( '1', '2', 'apple', 'banana' ), '1,2,apple,banana' ), 550 array( array( '1', '2', 'apple', 'banana' ), '1, 2,apple,banana' ), 551 array( array( '1', '2', 'apple', 'banana' ), '1,2,apple,,banana' ), 552 array( array( '1', '2', 'apple', 'banana' ), ',1,2,apple,banana' ), 553 array( array( '1', '2', 'apple', 'banana' ), '1,2,apple,banana,' ), 554 array( array( '1', '2', 'apple', 'banana' ), '1,2 ,apple,banana' ), 555 array( array(), '' ), 556 array( array(), ',' ), 557 array( array(), ',,' ), 558 ); 535 559 } 536 560 -
trunk/tests/phpunit/tests/rest-api/rest-controller.php
r43986 r44546 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' ); … … 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( 227 array( 228 'somestring', 229 'someinteger', 229 $this->assertEquals( $expected, $fields ); 230 } 231 232 public function data_get_fields_for_response() { 233 return array( 234 array( 235 'somestring,someinteger', 236 array( 237 'somestring', 238 'someinteger', 239 ), 230 240 ), 231 $fields 241 array( 242 ',,', 243 array( 244 'somestring', 245 'someinteger', 246 'someboolean', 247 'someurl', 248 'somedate', 249 'someemail', 250 'someenum', 251 'someargoptions', 252 'somedefault', 253 ), 254 ), 232 255 ); 233 256 } -
trunk/tests/phpunit/tests/rest-api/rest-schema-sanitization.php
r43571 r44546 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 … … 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 -
trunk/tests/phpunit/tests/rest-api/rest-schema-validation.php
r43571 r44546 121 121 $this->assertTrue( rest_validate_value_from_schema( array( 1 ), $schema ) ); 122 122 $this->assertWPError( rest_validate_value_from_schema( array( true ), $schema ) ); 123 $this->assertWPError( rest_validate_value_from_schema( null, $schema ) ); 123 124 } 124 125 … … 146 147 $this->assertTrue( rest_validate_value_from_schema( '1,2,3', $schema ) ); 147 148 $this->assertWPError( rest_validate_value_from_schema( 'lol', $schema ) ); 149 $this->assertTrue( rest_validate_value_from_schema( '1,,', $schema ) ); 150 $this->assertTrue( rest_validate_value_from_schema( '', $schema ) ); 148 151 } 149 152 … … 170 173 $this->assertTrue( rest_validate_value_from_schema( 'ribs,chicken', $schema ) ); 171 174 $this->assertWPError( rest_validate_value_from_schema( 'chicken,coleslaw', $schema ) ); 175 $this->assertTrue( rest_validate_value_from_schema( 'ribs,chicken,', $schema ) ); 176 $this->assertTrue( rest_validate_value_from_schema( '', $schema ) ); 172 177 } 173 178
Note: See TracChangeset
for help on using the changeset viewer.