[8.x] Ignore trailing delimiter in cache.headers options string #38910
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: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()
inSetCacheHeaders::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.