File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed
main/java/org/springframework/util
test/java/org/springframework/util Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -774,7 +774,9 @@ public static Locale parseLocale(String localeValue) {
774
774
if (tokens .length == 1 ) {
775
775
validateLocalePart (localeValue );
776
776
Locale resolved = Locale .forLanguageTag (localeValue );
777
- return (resolved .getLanguage ().length () > 0 ? resolved : null );
777
+ if (resolved .getLanguage ().length () > 0 ) {
778
+ return resolved ;
779
+ }
778
780
}
779
781
return parseLocaleTokens (localeValue , tokens );
780
782
}
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2018 the original author or authors.
2
+ * Copyright 2002-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -765,4 +765,20 @@ public void testAvailableLocalesWithLanguageTag() {
765
765
}
766
766
}
767
767
768
+ @ Test
769
+ public void testInvalidLocaleWithLocaleString () {
770
+ assertEquals (new Locale ("invalid" ), StringUtils .parseLocaleString ("invalid" ));
771
+ assertEquals (new Locale ("invalidvalue" ), StringUtils .parseLocaleString ("invalidvalue" ));
772
+ assertEquals (new Locale ("invalidvalue" , "foo" ), StringUtils .parseLocaleString ("invalidvalue_foo" ));
773
+ assertNull (StringUtils .parseLocaleString ("" ));
774
+ }
775
+
776
+ @ Test
777
+ public void testInvalidLocaleWithLanguageTag () {
778
+ assertEquals (new Locale ("invalid" ), StringUtils .parseLocale ("invalid" ));
779
+ assertEquals (new Locale ("invalidvalue" ), StringUtils .parseLocale ("invalidvalue" ));
780
+ assertEquals (new Locale ("invalidvalue" , "foo" ), StringUtils .parseLocale ("invalidvalue_foo" ));
781
+ assertNull (StringUtils .parseLocale ("" ));
782
+ }
783
+
768
784
}
You can’t perform that action at this time.
0 commit comments