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

[8.x] Ignore trailing delimiter in cache.headers options string #38910

Merged
merged 1 commit into from
Sep 22, 2021
Merged

Conversation

jobyh
Copy link
Contributor

@jobyh jobyh commented Sep 22, 2021

I recently tripped up on the fact that an options string passed to cache.headers middleware expects semicolon delimiters but results in the following exception if there is a semicolon following the last option:

InvalidArgumentException: Response does not support the following options: "".

It took me a couple of minutes including reading through the core code to realise what I'd done wrong. I think my confusion was caused by the fact semicolons may be used to terminate directive groups in HTTP header values and other string based options in Laravel e.g. validation rules use a comma delimiter. I made this mistake despite having just consulted the example in the docs.

Therefore this patch proposes trimming the trailing semicolon if it exists so that explode() in SetCacheHeaders::parseOptions() does not result in an additional empty string causing the error.

There are no breaking changes as existing option strings will continue to work.

This would benefit other developers by preventing an easy mistake causing confusion / requiring a little debugging time. It also mirrors modern PHP syntax where trailing delimiters are ignored e.g. arrays / arguments.

@taylorotwell taylorotwell merged commit 14c7b50 into laravel:8.x Sep 22, 2021
victorvilella pushed a commit to cdsistemas/framework that referenced this pull request Oct 12, 2021
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