fix(ui): rank Accept-Language tags by q-value instead of substring scan - #2084
Open
AmirF194 wants to merge 1 commit into
Open
fix(ui): rank Accept-Language tags by q-value instead of substring scan#2084AmirF194 wants to merge 1 commit into
AmirF194 wants to merge 1 commit into
Conversation
detect_ui_lang() (src/ui/http_server.c) picked the UI language with strstr(accept_language, "zh"), so any Chinese tag anywhere in the header served the Chinese UI regardless of position or q-value. A bilingual header whose top preference is English (e.g. en-US;q=0.9,zh;q=0.5) still got Chinese. Per RFC 9110 12.5.4, parse each tag's q-value (default 1.0), treat q=0 as explicitly unacceptable (12.5.1), and return the highest-ranked tag whose base language is zh or en, keeping the first occurrence on a tie. This mirrors the UI bundle's own JT() fallback parser, quoted in the issue, which already implements this correctly as a client-side fallback. Fixes DeusData#1829 Signed-off-by: Amir Fathi <amirfathi.me@gmail.com>
|
Thanks for opening this — it has been seen, and it is queued. This note is automated, but it is not a brush-off: it exists so you know where your PR stands instead of having to guess from silence. Current review status: working through a backlog. What that means for this PR, concretely:
Things that will genuinely speed it up whenever review does happen:
If this fixes a bug, a reproduction we can run is worth more than a description of the symptom. Thanks for contributing, and sorry in advance for the wait. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
detect_ui_lang()(src/ui/http_server.c) picks the/api/ui-configlanguage withstrstr(accept_language, "zh"), so any Chinese tag anywhere in the header serves the Chinese UI, regardless of position or q-value. A bilingual browser list whose top preference is English (en-US;q=0.9,zh;q=0.5) still gets Chinese.Per RFC 9110 12.5.4, the fix parses each tag's q-value (default 1.0), treats
q=0as explicitly unacceptable (12.5.1), and returns the highest-ranked tag whose base language iszhoren, keeping the first occurrence on a tie. This mirrors the UI bundle's ownJT()fallback parser (quoted in the issue), which already does this correctly as a client-side fallback when the endpoint is unreachable.Checklist
git commit -s)scripts/test.sh --suites httpd)Verification
"lang":"en"and get"lang":"zh"on plainmain; both pass on this branch. Ran both ways in a cleanubuntu:24.04container. Fullhttpdsuite: 66 passed, 1 skipped (pre-existing, Windows-only) on both sides.detect_ui_langhas a single call site (handle_ui_config); no other reader needed updating.cppcheckandclang-format --dry-runon the two changed files: same output before and after this change, so nothing new here.Fixes #1829