1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 08:12:21 +01:00

Fix GH-8924 str_split of empty string must return empty array

Closes #8945.
This commit is contained in:
Michael Voříšek
2022-07-07 12:49:09 +02:00
committed by David Carlier
parent 4df3dd7679
commit e80925445c
7 changed files with 25 additions and 15 deletions

3
NEWS
View File

@@ -13,6 +13,9 @@ PHP NEWS
- FPM:
. Added listen.setfib pool option to set route FIB on FreeBSD. (David Carlier)
- Standard:
. Fixed empty array returned by str_split on empty input. (Michael Vorisek)
07 Jul 2022, PHP 8.2.0alpha3
- Core:

View File

@@ -45,6 +45,7 @@ PHP 8.2 UPGRADE NOTES
stripos, strripos, lcfirst, ucfirst, ucwords, str_ireplace,
array_change_key_case and sorting with SORT_FLAG_CASE use ASCII case
conversion.
. str_split no longer returns an empty array on empty string.
- SPL:
. The following methods now enforce their signature:

View File

@@ -5885,7 +5885,11 @@ PHP_FUNCTION(str_split)
RETURN_THROWS();
}
if (0 == ZSTR_LEN(str) || (size_t)split_length >= ZSTR_LEN(str)) {
if ((size_t)split_length >= ZSTR_LEN(str)) {
if (0 == ZSTR_LEN(str)) {
RETURN_EMPTY_ARRAY();
}
array_init_size(return_value, 1);
add_next_index_stringl(return_value, ZSTR_VAL(str), ZSTR_LEN(str));
return;

View File

@@ -16,7 +16,11 @@ var_dump( str_split($str,$split_length) );
echo "-- With split_length as default argument --\n";
var_dump( str_split($str) );
echo "Done"
echo "-- Empty string must always return empty array --\n";
var_dump( str_split('') );
var_dump( str_split('', 1) );
var_dump( str_split('', 100) );
?>
--EXPECT--
*** Testing str_split() : basic functionality ***
@@ -80,4 +84,10 @@ array(22) {
[21]=>
string(1) "e"
}
Done
-- Empty string must always return empty array --
array(0) {
}
array(0) {
}
array(0) {
}

View File

@@ -39,9 +39,7 @@ echo "Done"
--EXPECTF--
*** Testing str_split() : double quoted strings for 'str' ***
-- Iteration 1 --
array(1) {
[0]=>
string(0) ""
array(0) {
}
-- Iteration 2 --
array(1) {

View File

@@ -38,9 +38,7 @@ echo "Done"
--EXPECT--
*** Testing str_split() : single quoted strings for 'str' ***
-- Iteration 1 --
array(1) {
[0]=>
string(0) ""
array(0) {
}
-- Iteration 2 --
array(1) {

View File

@@ -81,14 +81,10 @@ echo "Done"
--EXPECT--
*** Testing str_split() : heredoc strings as 'str' argument ***
-- Iteration 1 --
array(1) {
[0]=>
string(0) ""
array(0) {
}
-- Iteration 2 --
array(1) {
[0]=>
string(0) ""
array(0) {
}
-- Iteration 3 --
array(1) {