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

packages: fix up parse_accept_language() #19527

Merged

Commits on Oct 26, 2023

  1. packages: fix up parse_accept_language()

    Make several fixes to our handling of the `Accept-Language:` header:
    
     - we used to crash if `q=` contained invalid values due to an unchecked
       cast with `float()`.  Catch that error and ignore the entry in that
       case.
    
     - our handling of English was incorrect.  We would look for and fail to
       find po.en.js, and move on to the next item in the list.  That means
       if the user listed English first, followed by another language which
       we did support, they'd see Cockpit in that other language, which is
       unexpected.  This is a regression introduced by f4be906.  Now we
       drop all items that sort after English.
    
     - our handling of fallbacks (ie: 'de' from 'de-de') was incorrect.
       RFC4647 §3.4 says that a "Lookup" should consider items in the order
       they're found, stripping each item down to its base form, before
       considering the next item.  This passes a gut check, as well: a user
       who lists `de-de, nl` probably expects to see a German translation
       before a Dutch one.
    
    We also now mark the parser code as `@lru_cache`.  This makes sense:
    within a given run of cockpit-bridge, we're likely to see very many
    copies of the Accept-Language header, and they're practically always
    going to be identical.  Make sure we now accept and return immutable
    types to prevent weird side-effects.  We also take the time to remove
    duplicate items from the list.
    
    While we're at it, up our testing game a bit to make sure we don't
    mistreat requests for 'English' in the future.
    
    Closes cockpit-project#19526
    allisonkarlitskaya committed Oct 26, 2023
    Configuration menu
    Copy the full SHA
    1ac3bb2 View commit details
    Browse the repository at this point in the history