Skip to content
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

Update Str.php #35854

Closed
wants to merge 1 commit into from
Closed

Update Str.php #35854

wants to merge 1 commit into from

Conversation

rodrigokestler
Copy link

When $haystack is null or is not a string, mb_strpos throws a 500 PHP error. I'm not sure how I got the 500 error, but have three environments in the same server sharing the same database, all running the same app with different subdomains. Session is managed with the files drive, but cache uses the database driver. Two sites run as expected, and the other one wasn't able to handle the request. After checking the PHP error log:

[proxy_fcgi:error] [pid 256670] [client 190.104.120.178:59913] AH01071: Got error 'PHP message: PHP Fatal error: Uncaught TypeError: mb_strpos(): Argument #1 ($haystack) must be of type string, null given, called in /var/www/test2.readforall.com/vendor/laravel/framework/src/Illuminate/Support/Str.php on line 177 and defined in /var/www/test2.readforall.com/vendor/symfony/polyfill-mbstring/bootstrap80.php:60\nStack trace:\n#0 /var/www/test2.readforall.com/vendor/laravel/framework/src/Illuminate/Support/Str.php(177): mb_strpos()\n#1 /var/www/test2.readforall.com/vendor/laravel/framework/src/Illuminate/Http/Concerns/InteractsWithContentTypes.php(34): Illuminate\Support\Str::contains()\n#2 /var/www/test2.readforall.com/vendor/laravel/framework/src/Illuminate/Http/Request.php(371): Illuminate\Http\Request->isJson()\n#3 /var/www/test2.readforall.com/vendor/laravel/framework/src/Illuminate/Http/Request.php(435): Illuminate\Http\Request->getInputSource()\n#4 /var/www/test2.readforall.com/vendor/laravel/framework/src/Illuminate/Http/Request.php(64): Illuminate\Http\Request::createFromBase()\n#...'

And adding the propose change, I was able to run the application as expected.

When $haystack is null or is not a string, mb_strpos throws a 500 PHP error. I'm not sure how I got the 500 error, but have three environments in the same server sharing the same database, all running the same app with different subdomains. Session is managed with the files drive, but cache uses the database driver. Two sites run as expected, and the other one wasn't able to handle the request. After checking the PHP error log:

[proxy_fcgi:error] [pid 256670] [client 190.104.120.178:59913] AH01071: Got error 'PHP message: PHP Fatal error:  Uncaught TypeError: mb_strpos(): Argument laravel#1 ($haystack) must be of type string, null given, called in /var/www/test2.readforall.com/vendor/laravel/framework/src/Illuminate/Support/Str.php on line 177 and defined in /var/www/test2.readforall.com/vendor/symfony/polyfill-mbstring/bootstrap80.php:60\nStack trace:\n#0 /var/www/test2.readforall.com/vendor/laravel/framework/src/Illuminate/Support/Str.php(177): mb_strpos()\n#1 /var/www/test2.readforall.com/vendor/laravel/framework/src/Illuminate/Http/Concerns/InteractsWithContentTypes.php(34): Illuminate\\Support\\Str::contains()\n#2 /var/www/test2.readforall.com/vendor/laravel/framework/src/Illuminate/Http/Request.php(371): Illuminate\\Http\\Request->isJson()\n#3 /var/www/test2.readforall.com/vendor/laravel/framework/src/Illuminate/Http/Request.php(435): Illuminate\\Http\\Request->getInputSource()\n#4 /var/www/test2.readforall.com/vendor/laravel/framework/src/Illuminate/Http/Request.php(64): Illuminate\\Http\\Request::createFromBase()\n#...'

And adding the propose change, I was able to run the application as expected.
@antonkomarev
Copy link
Contributor

antonkomarev commented Jan 12, 2021

Add tests for this case, please

@driesvints
Copy link
Member

Seems to break the test suite.

@driesvints driesvints closed this Jan 12, 2021
@qindj
Copy link

qindj commented Jan 12, 2021

same issue here windows 10 + php 8.0.1 + Laravel Framework 8.21, full stacks:

`
[Tue Jan 12 17:28:12 2021] PHP Fatal error: Uncaught TypeError: mb_strpos(): Argument #1 ($haystack) must be of type string, null given, called in E:\Projects\测试项目\admin\vendor\laravel\framework\src\Illuminate\Support\Str.php on line 183 and defined in E:\Projects\测试项目\admin\vendor\symfony\polyfill-mbstring
bootstrap80.php:60
Stack trace:
#0 E:\Projects\测试项目\admin\vendor\laravel\framework\src\Illuminate\Support\Str.php(183): mb_strpos(NULL, '/json')

#1 E:\Projects\测试项目\admin\vendor\laravel\framework\src\Illuminate\Http\Concerns\InteractsWithContentTypes.php(16): Illuminate\Support\Str::contains(NULL, Array)

#2 E:\Projects\测试项目\admin\vendor\laravel\framework\src\Illuminate\Http\Request.php(371): Illuminate\Http\Request->isJson()

#3 E:\Projects\测试项目\admin\vendor\laravel\framework\src\Illuminate\Http\Request.php(435): Illuminate\Http\Request->getInputSource()

#4 E:\Projects\测试项目\admin\vendor\laravel\framework\src\Illuminate\Http\Request.php(64): Illuminate\Http\Request::createFromBase(Object(Symfony\Component\HttpFoundation\Request))

#5 E:\Projects\测试项目\admin\public\index.php(52): Illuminate\Http\Request::capture()

#6 E:\Projects\测试项目\admin\server.php(21): require_once('E:\Projects\\xE6\xB5\x8B...')

#7 {main}
thrown in E:\Projects\测试项目\admin\vendor\symfony\polyfill-mbstring\bootstrap80.php on line 60

`

@AEK-BKF
Copy link

AEK-BKF commented Jan 19, 2021

Same Here !!

@GrahamCampbell
Copy link
Member

See symfony/polyfill#329. In the meanwhile, you can work around this by downgrading to PHP 7.4.14, or installing ext-mbstring on PHP 8.0.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants