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

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

Comments

@spring-projects-issues
Copy link
Collaborator

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 https://tools.ietf.org/html/rfc4647#section-3.4.1)
And "ja" is supported.
So expected Locale is "ja".

Suggestion:

Change "languageMatch = candidate;"
at
https://github.com/spring-projects/spring-framework/blob/v5.0.4.RELEASE/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/AcceptHeaderLocaleResolver.java#L132
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

@spring-projects-issues
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.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Mar 19, 2018

Naozumi Taromaru commented

Thanks!

@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
Labels
in: web status: backported type: bug
Projects
None yet
Development

No branches or pull requests

2 participants