-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 #19526
- Loading branch information
1 parent
5be680e
commit 1ac3bb2
Showing
2 changed files
with
104 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters