-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Improve preg_* functions warnings for NUL byte #13068
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
Improve preg_* functions warnings for NUL byte #13068
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable to me
ext/pcre/tests/preg_grep_error1.phpt
Outdated
'/[a-zA-Z]/', //Regex string | ||
]; | ||
$array = [123, 'abc', 'test']; | ||
foreach ($values as $value) { | ||
@print "\nArg value is $value\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the print call suppressed here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise we get Warning: Array to string conversion in
. What do you think about removing this print, as this is not really necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh it's because of that nested array... I mean this will break in PHP 9 when we promote this sooooooo, removing it is probably fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for review. I removed unnecessary strings from those tests such:
- header of a test printed
value
printDone
string at the end of test
$subject = 'test'; | ||
foreach($regex_array as $regex_value) { | ||
foreach ($regex_array as $regex_value) { | ||
@print "\nArg value is $regex_value\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
$subject = 'this is a test'; | ||
foreach($regex_array as $regex_value) { | ||
foreach ($regex_array as $regex_value) { | ||
@print "\nArg value is $regex_value\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
function integer_word($matches) { | ||
global $replacement; | ||
return $replacement[$matches[0]]; | ||
} | ||
$subject = 'number 1.'; | ||
foreach($regex_array as $regex_value) { | ||
foreach ($regex_array as $regex_value) { | ||
@print "\nArg value is $regex_value\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
$replace = 1; | ||
$subject = 'a'; | ||
foreach($regex_array as $regex_value) { | ||
foreach ($regex_array as $regex_value) { | ||
@print "\nArg value is $regex_value\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
$subject = '1 2 a 3 4 b 5 6'; | ||
foreach($regex_array as $regex_value) { | ||
foreach ($regex_array as $regex_value) { | ||
@print "\nArg value is $regex_value\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
@@ -6,11 +6,9 @@ Test preg_match() function : error conditions - wrong arg types | |||
/* | |||
* Testing how preg_match reacts to being passed the wrong type of subject argument | |||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test seems to be a ZPP test, and should be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -8,28 +8,21 @@ Test preg_match_all() function : error conditions - wrong arg types | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test also looks like a ZPP test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
I thought that replacing
NUL
toNUL byte
brings more clarity what we expect as delimiter inpreg_*
functions.It can be replaced with
null character
,null terminator
, or maybe with explicitNUL (\0)
, but simpleNUL
can be mistaken with thenull
in PHP language. I was also confused when I was seeing this message for the first time.Additionally I formatted code of tests which were affected by this change.