Changeset 63366
- Timestamp:
- 08/27/2026 07:00:51 PM (2 months ago)
- Location:
- trunk
- Files:
-
- 4 edited
-
src/wp-includes/functions.php (modified) (4 diffs)
-
tests/phpunit/tests/functions/wpParseIdList.php (modified) (5 diffs)
-
tests/phpunit/tests/functions/wpParseList.php (modified) (3 diffs)
-
tests/phpunit/tests/functions/wpParseSlugList.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/functions.php
r63365 r63366 5028 5028 * 5029 5029 * @since 5.1.0 5030 * 5031 * @param mixed[]|string $input_list List of values. 5030 * @since 7.2.0 Added explicit support for passing an integer. 5031 * 5032 * @param mixed[]|string|int $input_list List of values. 5032 5033 * @return array Array of scalar values. A string is split into a list, while an array 5033 5034 * keeps its keys, so the result is not necessarily a list. 5034 5035 * @phpstan-return ( 5035 * $input_list is string ? list<string> : (5036 * $input_list is string|int ? list<string> : ( 5036 5037 * $input_list is array<string> ? array<string> : array<scalar> 5037 5038 * ) … … 5039 5040 */ 5040 5041 function wp_parse_list( $input_list ): array { 5041 if ( ! is_array( $input_list ) ) { 5042 if ( is_int( $input_list ) ) { 5043 $input_list = array( (string) $input_list ); 5044 } elseif ( ! is_array( $input_list ) ) { 5042 5045 $parsed_list = preg_split( '/[\s,]+/', $input_list, -1, PREG_SPLIT_NO_EMPTY ); 5043 5046 return is_array( $parsed_list ) ? $parsed_list : array(); … … 5054 5057 * 5055 5058 * @since 3.0.0 5056 * @since 5.1.0 Refactored to use wp_parse_list(). 5057 * 5058 * @param mixed[]|string $input_list List of IDs. 5059 * @since 5.1.0 Refactored to use {@see wp_parse_list()}. 5060 * @since 7.2.0 Added explicit support for passing an integer. 5061 * 5062 * @param mixed[]|string|int $input_list List of IDs. 5059 5063 * @return int[] Sanitized array of IDs. May include zero. Keys are preserved 5060 5064 * from the input and `array_unique()` may leave gaps, so the … … 5072 5076 * 5073 5077 * @since 4.7.0 5074 * @since 5.1.0 Refactored to use wp_parse_list(). 5075 * 5076 * @param mixed[]|string $input_list List of slugs. 5078 * @since 5.1.0 Refactored to use {@see wp_parse_list()}. 5079 * @since 7.2.0 Added explicit support for passing an integer. 5080 * 5081 * @param mixed[]|string|int $input_list List of slugs. 5077 5082 * @return string[] Sanitized array of slugs. May include an empty string. Keys 5078 5083 * are preserved from the input and `array_unique()` may leave -
trunk/tests/phpunit/tests/functions/wpParseIdList.php
r62797 r63366 17 17 * @dataProvider data_unexpected_input 18 18 * 19 * @param mixed[]|string $input_list19 * @param mixed[]|string|int $input_list 20 20 * @param array<non-negative-int> $expected 21 21 */ … … 38 38 * Data provider. 39 39 * 40 * @return array<string, array{ input_list: mixed[]|string , expected: array<non-negative-int> }>40 * @return array<string, array{ input_list: mixed[]|string|int, expected: array<non-negative-int> }> 41 41 */ 42 42 public function data_wp_parse_id_list(): array { … … 75 75 'expected' => array( 1, 2, 3, 4 ), 76 76 ), 77 'positive int' => array( 78 'input_list' => 5, 79 'expected' => array( 5 ), 80 ), 81 'negative int' => array( 82 'input_list' => -5, 83 'expected' => array( 5 ), 84 ), 85 'zero' => array( 86 'input_list' => 0, 87 'expected' => array( 0 ), 88 ), 77 89 ); 78 90 } … … 81 93 * Data provider. 82 94 * 83 * @return array<string, array{ input_list: mixed[]|string , expected: array<non-negative-int> }>95 * @return array<string, array{ input_list: mixed[]|string|int, expected: array<non-negative-int> }> 84 96 */ 85 97 public function data_unexpected_input(): array { … … 99 111 'array with spaces' => array( 100 112 'input_list' => array( '1 2 string with spaces' ), 113 'expected' => array( 1 ), 114 ), 115 'comma in array' => array( 116 'input_list' => array( '1,2' ), 101 117 'expected' => array( 1 ), 102 118 ), -
trunk/tests/phpunit/tests/functions/wpParseList.php
r62797 r63366 15 15 * @dataProvider data_wp_parse_list 16 16 * 17 * @param mixed[]|string $input_list17 * @param mixed[]|string|int $input_list 18 18 * @param array<scalar> $expected 19 19 */ … … 36 36 * Data provider. 37 37 * 38 * @return array<string, array{ input_list: mixed[]|string , expected: array<scalar> }>38 * @return array<string, array{ input_list: mixed[]|string|int, expected: array<scalar> }> 39 39 */ 40 40 public function data_wp_parse_list(): array { … … 84 84 'expected' => array(), 85 85 ), 86 'positive int' => array( 87 'input_list' => 5, 88 'expected' => array( '5' ), 89 ), 90 'negative int' => array( 91 'input_list' => -5, 92 'expected' => array( '-5' ), 93 ), 94 'zero' => array( 95 'input_list' => 0, 96 'expected' => array( '0' ), 97 ), 98 'comma in array item' => array( 99 'input_list' => array( '1,2' ), 100 'expected' => array( '1,2' ), 101 ), 86 102 'passed scalar array' => array( 87 103 'input_list' => array( 'foo', true, false, 1, 3.14 ), -
trunk/tests/phpunit/tests/functions/wpParseSlugList.php
r62797 r63366 17 17 * @dataProvider data_unexpected_input 18 18 * 19 * @param mixed[]|string $input_list19 * @param mixed[]|string|int $input_list 20 20 * @param array<string> $expected 21 21 */ … … 38 38 * Data provider. 39 39 * 40 * @return array<string, array{ input_list: mixed[]|string , expected: array<string> }>40 * @return array<string, array{ input_list: mixed[]|string|int, expected: array<string> }> 41 41 */ 42 42 public function data_wp_parse_slug_list(): array { … … 76 76 'expected' => array( 'apple', 'banana-carrot', 'd-o-g' ), 77 77 ), 78 'positive int' => array( 79 'input_list' => 5, 80 'expected' => array( '5' ), 81 ), 82 'negative int' => array( 83 'input_list' => -5, 84 'expected' => array( '5' ), 85 ), 86 'zero' => array( 87 'input_list' => 0, 88 'expected' => array( '0' ), 89 ), 78 90 'passed assoc array' => array( 79 91 'input_list' => array( … … 94 106 * Data provider. 95 107 * 96 * @return array<string, array{ input_list: mixed[]|string , expected: array<string> }>108 * @return array<string, array{ input_list: mixed[]|string|int, expected: array<string> }> 97 109 */ 98 110 public function data_unexpected_input(): array {
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)