Skip to content

strtok warns in case the string to split was not set. #10016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/standard/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ PHP_FUNCTION(strtok)

if (!BG(strtok_string)) {
/* String to tokenize not set. */
// TODO: Should this warn?
php_error_docref(NULL, E_WARNING, "Both arguments must be provided when starting tokenization");
RETURN_FALSE;
}

Expand Down
32 changes: 31 additions & 1 deletion ext/standard/tests/strings/strtok_variation3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ foreach($heredoc_strings as $string) {

echo "Done\n";
?>
--EXPECT--
--EXPECTF--
*** Testing strtok() : with heredoc strings ***

--- Iteration 1 ---
Expand All @@ -80,15 +80,35 @@ bool(false)

--- Iteration 2 ---
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

--- Iteration 3 ---
Expand Down Expand Up @@ -137,9 +157,19 @@ string(3) "rld"
string(4) "hell"
string(4) "hell"
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)
Done
20 changes: 19 additions & 1 deletion ext/standard/tests/strings/strtok_variation4.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,25 @@ foreach( $strings_with_nulls as $string ) {

echo "Done\n";
?>
--EXPECT--
--EXPECTF--
*** Testing strtok() : with embedded nulls in the strings ***

--- Iteration 1 ---
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

--- Iteration 2 ---
Expand Down Expand Up @@ -82,9 +92,17 @@ bool(false)
--- Iteration 6 ---
string(11) "hello world"
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

--- Iteration 7 ---
Expand Down
32 changes: 31 additions & 1 deletion ext/standard/tests/strings/strtok_variation5.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ foreach( $string_array as $string ) {

echo "Done\n";
?>
--EXPECT--
--EXPECTF--
*** Testing strtok() : with miscellaneous inputs ***

--- Iteration 1 ---
Expand All @@ -65,10 +65,20 @@ bool(false)

--- Iteration 2 ---
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

--- Iteration 3 ---
Expand Down Expand Up @@ -113,18 +123,38 @@ bool(false)

--- Iteration 8 ---
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

--- Iteration 9 ---
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

--- Iteration 10 ---
Expand Down
10 changes: 9 additions & 1 deletion ext/standard/tests/strings/strtok_variation6.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ foreach( $string_array as $string ) {

echo "Done\n";
?>
--EXPECT--
--EXPECTF--
*** Testing strtok() : with invalid escape sequences in token ***

--- Iteration 1 ---
Expand All @@ -69,6 +69,8 @@ bool(false)
string(1) " "
string(1) "r"
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)


Expand All @@ -91,11 +93,15 @@ bool(false)
string(5) "hello"
string(6) " world"
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

string(1) " "
string(1) "r"
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)


Expand All @@ -113,6 +119,8 @@ bool(false)
string(6) "hello\"
string(6) " world"
bool(false)

Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
bool(false)

string(1) "/"
Expand Down