Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring MVC in runtime fails when the locale is changed according with BCP 47 [SPR-16775] #21315

Closed
spring-projects-issues opened this issue Apr 26, 2018 · 3 comments
Assignees
Labels
in: web status: invalid

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Apr 26, 2018

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:

@spring-projects-issues spring-projects-issues added type: bug status: waiting-for-triage in: web labels Jan 11, 2019
@spring-projects-issues spring-projects-issues removed the type: bug label Jan 11, 2019
@virmundi
Copy link

virmundi commented 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
Copy link

charly077 commented Jul 8, 2019

We have a similar issue with release 2.0.6.RELEASE. Is it fixed on the newest version?

@sbrannen
Copy link
Member

sbrannen commented 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 languageTagCompliant property of LocaleChangeInterceptor to true for 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.

@sbrannen sbrannen closed this as completed Jul 9, 2019
@sbrannen sbrannen added status: invalid and removed status: waiting-for-triage labels Jul 9, 2019
@sbrannen sbrannen self-assigned this Jul 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web status: invalid
Projects
None yet
Development

No branches or pull requests

4 participants