Skip to content

Handle blank Accept-Language header in AcceptHeaderLocaleResolver#36513

Closed
elgunshukurov wants to merge 1 commit intospring-projects:7.0.xfrom
elgunshukurov:36512-accept-header-locale-resolver-blank-header
Closed

Handle blank Accept-Language header in AcceptHeaderLocaleResolver#36513
elgunshukurov wants to merge 1 commit intospring-projects:7.0.xfrom
elgunshukurov:36512-accept-header-locale-resolver-blank-header

Conversation

@elgunshukurov
Copy link

Problem

AcceptHeaderLocaleResolver.resolveLocale() correctly returns defaultLocale
when the Accept-Language header is absent (null), but ignores it when the
header is present with a blank value (""), falling back to Locale.getDefault()
(JVM system locale) instead.

Fix

Replace the null check with !StringUtils.hasText() which handles null,
empty string, and whitespace-only values consistently.

Root cause

// before
if (defaultLocale != null && request.getHeader("Accept-Language") == null) {

// after  
if (defaultLocale != null && !StringUtils.hasText(request.getHeader("Accept-Language"))) {

Closes gh-36512

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Mar 22, 2026
@elgunshukurov elgunshukurov force-pushed the 36512-accept-header-locale-resolver-blank-header branch from c08f39e to 017ed7a Compare March 22, 2026 15:45
@bclozel bclozel added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Mar 22, 2026
@bclozel bclozel added this to the 7.0.7 milestone Mar 22, 2026
@bclozel bclozel self-assigned this Mar 22, 2026
@bclozel
Copy link
Member

bclozel commented Mar 22, 2026

@elgunshukurov at this stage we try to avoid introducing behavior changes in the 6.2.x line. Can you rebase against 7.0.x please?

@elgunshukurov elgunshukurov force-pushed the 36512-accept-header-locale-resolver-blank-header branch from 017ed7a to ac36fb5 Compare March 22, 2026 16:42
@elgunshukurov elgunshukurov changed the base branch from 6.2.x to 7.0.x March 22, 2026 16:42
@elgunshukurov elgunshukurov force-pushed the 36512-accept-header-locale-resolver-blank-header branch from ac36fb5 to 7d3bc31 Compare March 22, 2026 16:45
@elgunshukurov
Copy link
Author

@bclozel done, rebased against 7.0.x. Thanks for the guidance.

@bclozel bclozel force-pushed the 36512-accept-header-locale-resolver-blank-header branch from 7d3bc31 to f6fe557 Compare March 23, 2026 13:28
When the Accept-Language header is present but blank, defaultLocale
was ignored and fell back to Locale.getDefault() (JVM system locale).
A blank header represents the same intent as an absent header.

Closes spring-projectsgh-36513

Signed-off-by: elgun.shukurov <elgun.sukurov@kapitalbank.az>
@bclozel bclozel force-pushed the 36512-accept-header-locale-resolver-blank-header branch from f6fe557 to 4b21164 Compare March 23, 2026 13:28
@bclozel bclozel closed this in 4b21164 Mar 23, 2026
@bclozel
Copy link
Member

bclozel commented Mar 23, 2026

Thanks for your contribution @elgunshukurov this has been merged in 7.0.x and main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants