Closed silentjohnny closed 9 years ago
I couldn't find anything in the specs saying that the languages that appear first in the Accept-Language
header should have higher priority than the rest.
I would consider making this change if there was any indication that this is expected in practice but I haven't found anything so far.
To help decide, from RFC 7231 5.3.5:
Note that some recipients treat the order in which language tags are listed as an indication of descending priority, particularly for tags that are assigned equal quality values (no value is the same as q=1). However, this behavior cannot be relied upon. For consistency and to maximize interoperability, many user agents assign each language tag a unique quality value while also listing them in order of decreasing quality. Additional discussion of language priority lists can be found in Section 2.3 of RFC4647.
i'd prefer not to make this change and return types as i, the developer, supplies them to negotiator
That would be nice, but this is exactly not what V8 does. Array#sort changes the original order. Which means you can not assume.
This was an issue I raised before with Express when the sorting of accept headers was still done there. Since v8 uses quicksort (which is not a stable sort) for arrays longer than 10 elements, the sort order of 'equal' elements is not guaranteed to be the same as the original array. If you put this to the test in for example preferred languages, you get the following results:
should sort as
likewise,
should sort as
but instead sorts as
Not sure if this should be a real problem, but I think people assume that the order of the preferred languages in their browser is honored. But of course only if they have more than 10 preferred languages.
Any thoughts on whether this is a problem or not? I see a closed issue from TJ from last year.