Skip to content

fix(graph-ui): rank Accept-Language by q instead of substring match - #1313

Open
lukiod wants to merge 1 commit into
DeusData:mainfrom
lukiod:fix/accept-language-q-ranking
Open

fix(graph-ui): rank Accept-Language by q instead of substring match#1313
lukiod wants to merge 1 commit into
DeusData:mainfrom
lukiod:fix/accept-language-q-ranking

Conversation

@lukiod

@lukiod lukiod commented Jul 28, 2026

Copy link
Copy Markdown

What does this PR do?

detectLanguage tested whether "zh" appeared anywhere in the header, so any visitor whose Accept-Language mentions Chinese got the Chinese UI regardless of preference.

Header Before Expected
en-US,en;q=0.9,zh;q=0.5 zh en
zh;q=0, en zh en

The 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, drops q=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

  • Every commit is signed off (git commit -s)
  • Tests pass locally (make -f Makefile.cbm test)
  • Lint passes (make -f Makefile.cbm lint-ci)
  • New behavior is covered by a test (reproduce-first for bug fixes)

The two unticked items are the C toolchain, which this change does not touch and which I have not set up. For graph-ui I ran its own suite:

npx vitest run   9 files, 38 tests passed
npx tsc -b       clean

Happy to run the C targets too if you would like that before merging.

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>
@lukiod
lukiod requested a review from DeusData as a code owner July 28, 2026 03:21
@DeusData DeusData added bug Something isn't working ux/behavior Display bugs, docs, adoption UX labels Jul 28, 2026
@DeusData DeusData added this to the 0.9.1-rc milestone Jul 28, 2026
@DeusData DeusData added the priority/normal Standard review queue; useful PR with ordinary maintainer urgency. label Jul 28, 2026
@DeusData

DeusData commented Jul 28, 2026

Copy link
Copy Markdown
Owner

Thank you for the contribution and for covering both preference ordering and q=0 in the graph UI language negotiation. This is now triaged as a normal-priority UX bug for 0.9.1-rc. Our community PR queue is currently quite full, so it may take a little time before we can complete the review and, if approved, merge it. We are doing our best to support community contributions and will return with code-grounded feedback as capacity opens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working priority/normal Standard review queue; useful PR with ordinary maintainer urgency. ux/behavior Display bugs, docs, adoption UX

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants