From 773ec5734187c7790462bcc9a45a909b6eb99ea7 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Mon, 28 Nov 2022 20:40:32 +0000 Subject: [PATCH 1/2] strtok warns in case the string to split was not set. --- ext/standard/string.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/standard/string.c b/ext/standard/string.c index feaf568745ab4..0ce06c1b3b460 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -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, "First call must set the string argument to tokenize with `%s`", ZSTR_VAL(tok)); RETURN_FALSE; } From e14cfbc8beac63e71f28d50fe9d8dee7d8376bd2 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Mon, 28 Nov 2022 21:18:14 +0000 Subject: [PATCH 2/2] update tests --- ext/standard/string.c | 2 +- .../tests/strings/strtok_variation3.phpt | 32 ++++++++++++++++++- .../tests/strings/strtok_variation4.phpt | 20 +++++++++++- .../tests/strings/strtok_variation5.phpt | 32 ++++++++++++++++++- .../tests/strings/strtok_variation6.phpt | 10 +++++- 5 files changed, 91 insertions(+), 5 deletions(-) diff --git a/ext/standard/string.c b/ext/standard/string.c index 0ce06c1b3b460..bd8ea063d9a57 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -1080,7 +1080,7 @@ PHP_FUNCTION(strtok) if (!BG(strtok_string)) { /* String to tokenize not set. */ - php_error_docref(NULL, E_WARNING, "First call must set the string argument to tokenize with `%s`", ZSTR_VAL(tok)); + php_error_docref(NULL, E_WARNING, "Both arguments must be provided when starting tokenization"); RETURN_FALSE; } diff --git a/ext/standard/tests/strings/strtok_variation3.phpt b/ext/standard/tests/strings/strtok_variation3.phpt index 8ae1e03e7dba8..d5cf1ad91dba4 100644 --- a/ext/standard/tests/strings/strtok_variation3.phpt +++ b/ext/standard/tests/strings/strtok_variation3.phpt @@ -62,7 +62,7 @@ foreach($heredoc_strings as $string) { echo "Done\n"; ?> ---EXPECT-- +--EXPECTF-- *** Testing strtok() : with heredoc strings *** --- Iteration 1 --- @@ -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 --- @@ -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 diff --git a/ext/standard/tests/strings/strtok_variation4.phpt b/ext/standard/tests/strings/strtok_variation4.phpt index 63090497097f9..671cf74b03138 100644 --- a/ext/standard/tests/strings/strtok_variation4.phpt +++ b/ext/standard/tests/strings/strtok_variation4.phpt @@ -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 --- @@ -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 --- diff --git a/ext/standard/tests/strings/strtok_variation5.phpt b/ext/standard/tests/strings/strtok_variation5.phpt index 006cf7a9f9607..bc33315b960f1 100644 --- a/ext/standard/tests/strings/strtok_variation5.phpt +++ b/ext/standard/tests/strings/strtok_variation5.phpt @@ -52,7 +52,7 @@ foreach( $string_array as $string ) { echo "Done\n"; ?> ---EXPECT-- +--EXPECTF-- *** Testing strtok() : with miscellaneous inputs *** --- Iteration 1 --- @@ -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 --- @@ -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 --- diff --git a/ext/standard/tests/strings/strtok_variation6.phpt b/ext/standard/tests/strings/strtok_variation6.phpt index 9b3f1d244d81f..255c100a0b194 100644 --- a/ext/standard/tests/strings/strtok_variation6.phpt +++ b/ext/standard/tests/strings/strtok_variation6.phpt @@ -42,7 +42,7 @@ foreach( $string_array as $string ) { echo "Done\n"; ?> ---EXPECT-- +--EXPECTF-- *** Testing strtok() : with invalid escape sequences in token *** --- Iteration 1 --- @@ -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) @@ -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) @@ -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) "/"