fix(graph-ui): rank Accept-Language by q instead of substring match - #1313
Open
lukiod wants to merge 1 commit into
Open
fix(graph-ui): rank Accept-Language by q instead of substring match#1313lukiod wants to merge 1 commit into
lukiod wants to merge 1 commit into
Conversation
detectLanguage tested whether "zh" appeared anywhere in the header, so any
visitor whose Accept-Language mentions Chinese got the Chinese UI regardless of
preference.
en-US,en;q=0.9,zh;q=0.5 -> zh, expected en
zh;q=0, en -> zh, expected en
The first is a bilingual visitor who prefers English and lists Chinese as a
fallback. The second sets q=0, which RFC 7231 defines as not acceptable.
Now parses q, drops q=0, sorts descending, and matches the primary subtag rather
than a substring. Chinese still wins whenever it is actually preferred.
The two existing assertions are unchanged and still pass.
Signed-off-by: lukiod <mohakgupta0981@gmail.com>
Owner
|
Thank you for the contribution and for covering both preference ordering and |
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?
detectLanguagetested whether"zh"appeared anywhere in the header, so any visitor whoseAccept-Languagementions Chinese got the Chinese UI regardless of preference.en-US,en;q=0.9,zh;q=0.5zhenzh;q=0, enzhenThe first is the common case: a bilingual visitor who prefers English and lists Chinese as a fallback. That is a normal Chrome language configuration, and it currently produces a Chinese interface for someone who asked for English.
The second sets
q=0, which RFC 7231 defines as not acceptable — the header explicitly excludes Chinese and it was served anyway.Now parses
q, dropsq=0, sorts descending, and matches the primary subtag rather than a substring. Chinese still wins whenever it is actually preferred, and the two existing assertions are unchanged and still pass.Reproduce-first: both rows above are in the new tests and fail against the previous implementation.
Checklist
git commit -s)make -f Makefile.cbm test)make -f Makefile.cbm lint-ci)The two unticked items are the C toolchain, which this change does not touch and which I have not set up. For
graph-uiI ran its own suite:Happy to run the C targets too if you would like that before merging.