Repository navigation
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
Activity
virmundi commentedon Jan 26, 2019
I have the same issue with Spring Boot release 2.1.2.RELEASE. If I revert to 2.0.0.RELEASE it works fine.
charly077 commentedon Jul 8, 2019
We have a similar issue with release 2.0.6.RELEASE. Is it fixed on the newest version?
sbrannen commentedon Jul 9, 2019
Since Spring Framework 5.1, this should no longer be an issue (see commit 88e4006).
From Spring Framework 4.3 to 5.0, you would need to set the
languageTagCompliantproperty ofLocaleChangeInterceptortotruefor BCP 47 compliance (see commit 0dd320f).I am therefore closing this issue.
However, if you find that the above is not the case, please add a comment here with details.