willdurand / Negotiation

Content Negotiation tools for PHP.
https://williamdurand.fr/Negotiation/
MIT License
1.41k stars 62 forks source link

'*' preferred over earlier specified language #83

Open brianjmiller opened 8 years ago

brianjmiller commented 8 years ago

Given a list of languages like:

['en-US' => '...', 'en-UK' => '....']

And a language string of:

en-US, *

I get the value for en-UK using getBest and based on my (admittedly new) reading of the RFC suggests that I should get the 'en-US' value since it is listed first and they have the same quality factor. (Common sense suggests that is the better value.)

Switching the accept string to be en-US, *;q=0 resolves the matter but seems either incorrect or at least unnecessary.

Am I doing something wrong or is this a bug? It looked similar to some of the other open issues, but not quite the same. It also wasn't a problem in the 1.x release series.

mcaskill commented 7 years ago

I'm having this issue with the Accept request HTTP header.

My given accepted content types:

[ 'application/json', 'text/html', 'application/xhtml+xml', 'application/xml' ]

MSIE11

Chrome

The solution I used is similar to yours, I forced a lower priority on the wildcard:

preg_replace('/(\*\/\*)(?!;q=)/i', '$1;q=0.8', getenv('HTTP_ACCEPT'));