Skip to content

fix(hosting): skip Accept-Language candidates with q<=0 or non-finite q - #795

Closed
ShahadatTest wants to merge 1 commit into
antosubash:mainfrom
ShahadatTest:fix/locale-q0
Closed

ShahadatTest wants to merge 1 commit into
antosubash:mainfrom
ShahadatTest:fix/locale-q0

Conversation

@ShahadatTest

Copy link
Copy Markdown

Summary

  • LocaleMiddleware._negotiate skips Accept-Language entries with q<=0 (RFC 9110 §12.4.2 “not acceptable”) and non-finite q values (nan/inf).
  • Regression coverage for es;q=0 falling through to the default, and for non-finite weights not winning the sort.

Fixes #792

Test plan

  • uv run --package simple_module_hosting --with pytest --with python-multipart --with pytest-benchmark pytest framework/hosting/tests/test_locale_middleware.py -q -o addopts= (11 passed)

AI disclosure: This contribution was prepared with assistance from Cursor (AI). I reviewed and verified the change and tests before opening this PR.

LocaleMiddleware._negotiate treated q=0 like any other weight, so
Accept-Language: es;q=0 selected es. Skip not-acceptable and nan/inf
weights so negotiation falls through to a real preference or default.

Fixes antosubash#792
@antosubash antosubash closed this Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hosting: LocaleMiddleware selects Accept-Language entries with q=0

2 participants