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

BUG - CHttpRequest - the sort function for preferred languages and content types does not take into account the original item order #2429

Closed
Rupert-RR opened this issue Apr 30, 2013 · 1 comment

Comments

Projects
None yet
4 participants
@Rupert-RR
Copy link
Contributor

commented Apr 30, 2013

I have only just realised this, and for some reason I never came across a case where it was an issue before.
The sorting of the Accept and Accept-Language headers is done using the native usort function with a custom compare function. I had assumed that this would preserve the original order when items compared as equal, however it turns out that the usort function is not stable

The cmp_function doesn't keep the original order for elements comparing as equal

This means that lists of items with identical 'q' values will not necessarily be ordered correctly (earlier elements should have priority over later ones).

I will submit a pull request with a fix for this, and to make the getPreferredLanguages function more like its accept types counterpart (returning an array map, including the calculated 'q' values rather than just the language code, so that the content negotiation can use these 'q' values).

The original issues were #1673 for the Accept-Language parsing and #2131 and #2132 for the Accept header parsing.

Rupert-RR pushed a commit to Rupert-RR/yii that referenced this issue Apr 30, 2013

Rupert-RR
Fixes issue yiisoft#2429 by adding the class methods
parseAcceptLanguagesHeader() and compareAcceptLanguages as the
equivalents of the existing parseAcceptHeader() and
compareAcceptTypes(), and the instance method getAcceptLanguages() as
the equivalent of the existing getAcceptTypes().
Modified the parseAcceptHeader() method to include the original array
position in the resulting accept types array map.
Modified the compareAcceptTypes() method to take into account the
original position of the items when comparing is equal on all other
counts.
Modified the existing getPreferredLanguages() method to function in the
same way as the getPreferredAcceptTypes() method, and modified the
getPreferredLanguage() method to correctly interpret the resulting array
of array maps (rather than array of language strings as previously), so
that these changes should be transparent to anyone using this function.
Updated the unit tests for the parseAcceptHeader() and
compareAcceptTypes() methods and added tests for the new
parseAcceptLanguagesHeader() and compareAcceptLanguages() methods.

@ghost ghost assigned cebe Apr 30, 2013

@pawzar

This comment has been minimized.

Copy link
Contributor

commented Feb 5, 2014

This seems to be fixed.

@samdark samdark closed this Feb 5, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.