-
Notifications
You must be signed in to change notification settings - Fork 11.7k
Description
- Laravel Version: 8.22.1
- PHP Version: 8.0.1
- Database Driver & Version: mysql 15.1/mariaDB 10.2.36
Description:
The string support method contains throws an exception when $haystack is not a string.
Example:
Running any request that interacts with the InteractsWithContentTypes trait and uses the isJson method crashes. Make sure to send the request without a content-type header, this causes the $haystack variable to be null and throws an exception.
Php 8.0.0 and older always returned false
Php 8.0.1 throws an exception
Steps To Reproduce:
Install the above php version and laravel version. Request an API without a content-type header. Response should be a 500 server error.
The following code is what crashes.
public static function contains($haystack, $needles)
{
foreach ((array) $needles as $needle) {
if ($needle !== '' && mb_strpos($haystack, $needle) !== false) {
return true;
}
}
return false;
}
Exception: Uncaught TypeError: mb_strpos(): Argument #1 ($haystack) must be of type string, null given
The contains method should either type-hint a string or internally check if its a string.