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

Wrong ordering of candidates #10

Open
GoogleCodeExporter opened this issue May 13, 2015 · 0 comments
Open

Wrong ordering of candidates #10

GoogleCodeExporter opened this issue May 13, 2015 · 0 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?

    mimeparse.best_match(["image/jpeg", "text/plain"], "text/*;q=0.3, text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4, */*;q=0.5")

What is the expected output? What do you see instead?

Expected: 'image/jpeg'
Instead: 'text/plain'

What version of the product are you using? On what operating system?

Version: 0.1.3
OS: Mac OS X 10.6.4, Python 2.6.1
(Using Python version of mimeparse library)

Please provide any additional information below.

The best_match function is using fitness_and_quality_parsed() to order the 
candidate media ranges, but the first value from that is the fitness, which 
corresponds to what rfc2616 calls the "precedence", or the specificity of the 
range to the particular candidate type. The specificity matters, but the major 
ordering factor should be the quality (the client's measure of which media 
ranges are most preferred).

In the example above, image/jpeg should have a quality of 0.5 (from the */*) 
and text/plain should have a quality of 0.3 (from the text/*). The type with 
the higher quality factor is image/jpeg, and it should win.

I'm attaching a patch that fixes this by swapping the elements returned by 
fitness_and_quality_parsed(), along with an extra test for your suite. Hope 
this helps.

Original issue reported on code.google.com by pcannon@gmail.com on 15 Sep 2010 at 11:28

Attachments:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant