Skip to content

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

Closed

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

Activity

  1. spring-projects-issues commented on Mar 16, 2018

    @spring-projects-issues
    CollaboratorAuthor

    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.

  2. spring-projects-issues commented on Mar 19, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Naozumi Taromaru commented

    Thanks!

  3. added
    type: bug
    status: backported
    in: web
    on Jan 11, 2019
  4. added this to the 5.0.5 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webstatus: backportedtype: bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions