Skip to content

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

Closed
@spring-projects-issues

Description

@spring-projects-issues

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

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions