Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AcceptHeaderLocaleResolver chooses wrong Locale for language match [SPR-16599] #21140

spring-projects-issues opened this issue Mar 16, 2018 · 2 comments
in: web status: backported type: bug


Copy link

spring-projects-issues commented Mar 16, 2018

Naozumi Taromaru opened SPR-16599 and commented

Order of Locale in Accept-Language Header is slighted in AcceptHeaderLocaleResolver.

For example:

supportedLocales of AcceptHeaderLocaleResolver: ja, en_US, en
Accept-Language of Request: ja-JP,en-US;q=0.5
Expected: ja
Actual: en_US

"ja-JP,en-US;q=0.5" is meaning as "ja-JP > ja > en-US > en".
(Reference: Last "For example" of
And "ja" is supported.
So expected Locale is "ja".


Change "languageMatch = candidate;"
to "return candidate;".
And delete languageMatch(always null).

Affects: 5.0.4

Reference URL: #21002

Issue Links:

Referenced from: commits 6e1cac9, f8588e3

Backported to: 4.3.15

Copy link
Collaborator Author

spring-projects-issues commented Mar 16, 2018

Juergen Hoeller commented

I've refined the algorithm slightly differently: We still check for full language+country match in the supported locales even for later Accept-Language entries... but only if their language part matches, i.e. only if they narrow the primary language to a specific country. This is necessary for backwards compatibility in always finding the most specific match possible: e.g. en-UK in case of en-US,en-UK in the accept header and Locale.ENGLISH, Locale UK as the supported locales.

Copy link
Collaborator Author

spring-projects-issues commented Mar 19, 2018

Naozumi Taromaru commented


@spring-projects-issues spring-projects-issues added type: bug status: backported in: web labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 5.0.5 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
in: web status: backported type: bug
None yet

No branches or pull requests

2 participants