Skip to content

Sort order is not stable in Accept class #1686

Description

@lincolnq
    from werkzeug.datastructures import LanguageAccept
    from werkzeug.http import parse_accept_header

    a = parse_accept_header("en-US,fr-FR", LanguageAccept)
    assert a.best == "en-US"  # fails, it returns fr-FR

I expected the order to be preserved.

RFC 3282 describes desired behavior for Accept-Language: "If no Q values are given, the language-ranges are given in priority order, with the leftmost language-range being the most preferred language; this is an extension to the HTTP/1.1 rules, but matches current practice."

Looking at the source code, the Accept class is reverse-sorting the input list by specificity, then quality, then name; I think it should not sort by name and instead should preserve the given order.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions