Description
Manuel Jordan opened SPR-16775 and commented
I have the following infrastructure:
@Bean
public LocaleChangeInterceptor localeChangeInterceptor(){
LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
localeChangeInterceptor.setParamName("language");
return localeChangeInterceptor;
}
@Bean(name="localeResolver")
public LocaleResolver cookieLocaleResolver(){
CookieLocaleResolver cookieLocaleResolver = new CookieLocaleResolver();
cookieLocaleResolver.setCookieName("language");
cookieLocaleResolver.setDefaultLocale(Locale.forLanguageTag("en-US"));
return cookieLocaleResolver;
}
I have confirmed that in runtime
the following works:
(A): [http://localhost:8080/thymeleaf-02/locale/changelocale?language=es_ES]
Observe that the URL uses _
, and the app works.
(B) [http://localhost:8080/thymeleaf-02/locale/changelocale?language=es-ES]
Observe that the URL uses -
, and the app fails with:
HTTP Status 500 – Internal Server Error
Type Exception Report
Message Request processing failed; nested exception is java.lang.IllegalArgumentException: Locale part "es-ES" contains invalid characters
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: Locale part "es-ES" contains invalid characters
...
Root Cause
java.lang.IllegalArgumentException: Locale part "es-ES" contains invalid characters
org.springframework.util.StringUtils.validateLocalePart(StringUtils.java:817)
According with my experience in: #20999
Is valid use - and not _. Currently my @Test
methods pass with -
but fails in runtime
.
Is it a bug? Or missing configuration? Because I think runtime
and testing
should have the same behavior.
I know that BCP 47
for this case is about the Accept-Language
header and the URL is working through a parameter. But I hope you see my point.
Not sure if it is the expected behavior, but could be confuse for the developer.
Thank You.
Affects: 5.0.4
Issue Links:
- MockHttpServletRequest.addHeader fails for invalid LanguageRange in Accept-Language [SPR-16454] #20999 MockHttpServletRequest.addHeader fails for invalid LanguageRange in Accept-Language