Skip to content

Comments

WW-5549 Fix I18nInterceptor supportedLocale breaking request_locale#1594

Open
lukaszlenart wants to merge 1 commit intomainfrom
fix/WW-5549-i18n-supportedlocale-breaks-request-locale
Open

WW-5549 Fix I18nInterceptor supportedLocale breaking request_locale#1594
lukaszlenart wants to merge 1 commit intomainfrom
fix/WW-5549-i18n-supportedlocale-breaks-request-locale

Conversation

@lukaszlenart
Copy link
Member

Summary

Fixes WW-5549

  • Fix request_locale / request_cookie_locale parameters being ignored when supportedLocale is configured on the I18nInterceptor
  • Apply supportedLocale as a global filter on all locale sources (request params, session, cookies)
  • Reject stale session/cookie locales when supportedLocale configuration changes

Problem

When supportedLocale was configured, AcceptLanguageLocaleHandler.find() matched the Accept-Language header before SessionLocaleHandler / CookieLocaleHandler could check their explicit locale parameters (request_locale, request_cookie_locale). This made it impossible to switch locale via request parameters.

Additionally, supportedLocale was only applied to Accept-Language matching — locales from request params, session storage, and cookies were never validated against it.

Changes

  • Reorder locale resolution priority: explicit request parameters (request_locale, request_cookie_locale) are now checked before Accept-Language fallback
  • Add isLocaleSupported() helper: validates a locale against the supportedLocale set (no-op when empty, preserving backward compatibility)
  • Filter all locale sources: request params, session-stored locales, and cookie-stored locales are all validated against supportedLocale
  • Add 4 test cases covering the bug scenario and supportedLocale filtering

Test plan

  • All 18 tests in I18nInterceptorTest pass (14 existing + 4 new)
  • Verify request_locale works with supportedLocale configured (SESSION storage)
  • Verify unsupported request_locale is rejected and falls back
  • Verify stale session locale is rejected when supportedLocale changes
  • Verify request_cookie_locale works with supportedLocale (COOKIE storage)
  • Full backward compatibility when supportedLocale is not configured

🤖 Generated with Claude Code

…e when supportedLocale is configured

When supportedLocale was configured on the I18nInterceptor, the Accept-Language
header match in AcceptLanguageLocaleHandler.find() returned early before
SessionLocaleHandler/CookieLocaleHandler ever checked their explicit locale
parameters (request_locale, request_cookie_locale). This made it impossible
to switch locale via request parameters when supportedLocale was set.

Changes:
- Reorder AcceptLanguageLocaleHandler.find() to check request_only_locale
  before Accept-Language matching
- Reorder SessionLocaleHandler.find() to check request_locale before super
- Reorder CookieLocaleHandler.find() to check request_cookie_locale before super
- Add isLocaleSupported() helper to validate locales against supportedLocale
- Filter all locale sources (params, session, cookies) through supportedLocale
- Add 4 tests covering the bug scenario and supportedLocale filtering

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
69.0% Coverage on New Code (required ≥ 80%)
9.3% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant