Repository navigation
Conversation
A wildcard returned the first supported value even when the header excluded that value with q=0. For example, `Accept-Encoding: gzip;q=0, *` selected gzip, `Accept: application/json;q=0, */*` selected application/json, and `Accept: text/*, text/html;q=0` selected text/html. The same applied to `charset()`, and to `language()` with and without strict locale negotiation. A wildcard now skips the supported values that the header excludes. Without a match, the fallback to the first supported value when `$strictMatch` is false is unchanged.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
When the header holds a wildcard,
Negotiatereturns the first supported value, even if the same header excludes that value withq=0. In RFC 9110, a weight of 0 means "not acceptable" (section 12.4.2), and a more specific entry overrides a wildcard (sections 12.5.1 and 12.5.3). Examples:Accept-Encoding: gzip;q=0, *withencoding(['gzip', 'br'])returnsgzip.Accept: application/json;q=0, */*withmedia(['application/json', 'text/html'], true)returnsapplication/json.Accept: text/*, text/html;q=0withmedia(['text/html', 'text/plain'], true)returnstext/html.charset()behaves the same way, and so doeslanguage(), with and without$strictLocaleNegotiation. For example,Accept-Language: en;q=0, *givesen.getBestMatch()andgetBestLocaleMatch()now skip values that the header excludes when they match through a wildcard (*,*/*ortype/*). A new privateisExcluded()helper does the check. An exact match with a positive weight is unaffected. When nothing matches,$strictMatch = falsestill falls back to the first supported value, as documented and astestBestMatchOnlyLowQualityexpects.testWildcardsSkipExcludedValuesintests/system/HTTP/NegotiateTest.phpcoversmedia(),charset(),encoding()andlanguage(), including the strict locale negotiation path. Without the change it fails ('application/json'is returned instead of'text/html'). Thev4.7.6changelog has a Bugs Fixed entry.tests/system/HTTP/passes. php-cs-fixer, PHPStan and Rector (dry run) report nothing for the changed files.Checklist: