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

Only parse APP_URL for default stateful domains when it's set #279

Merged
merged 1 commit into from
May 19, 2021

Conversation

dshoreman
Copy link
Contributor

Problem

If APP_URL is not defined in the .env, the config breaks on PHP 8.1 with a null string deprecation. Since it has to load in the service provider, artisan and composer are broken too (not sure about new installs though—I only have 8.1 via GH actions).

For older versions, it's less of an issue - it merely adds '' to the sanctum.stateful array. Looks scary from a distance, but there's an array_filter() in the middleware so it's harmless... I think.

Introduced in v2.9.3 via #264.

Notes

A simple env('APP_URL', '') would suffice for the 8.1 issue, but it still leaves the extra empty entry in sanctum.stateful. To remove any chance of worry/risk/ambiguity, this PR makes the whole thing conditional on APP_URL being defined.

If APP_URL is missing then null is passed to parse_url(), which breaks
on PHP 8.1 even when you're only running composer install. On PHP <==8
it wouldn't error, but you'd have an empty entry in sanctum.stateful.

Setting SANCTUM_STATEFUL_DOMAINS in the project's .env isn't enough
because the default config is still merged in the service provider as
long as config isn't cached (which it won't be during composer install).

---

Also removes APP_URL from phpunit.xml, setting in the test that needs it
instead. By using getEnvironmentSetUp instead of @environment-setup, we
don't need putenv everywhere and it more closely matches other tests.
@taylorotwell taylorotwell merged commit 37da283 into laravel:2.x May 19, 2021
@dshoreman dshoreman deleted the fix/null-config-appUrl branch May 21, 2021 22:31
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.

2 participants