HHH-8207 - Locale conversion is broken
Conflicts: hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocaleTypeDescriptor.java
This commit is contained in:
parent
700ec50bea
commit
860c1fdab7
|
@ -59,10 +59,15 @@ public class LocaleTypeDescriptor extends AbstractTypeDescriptor<Locale> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Locale fromString(String string) {
|
public Locale fromString(String string) {
|
||||||
StringTokenizer tokens = new StringTokenizer( string, "_" );
|
// TODO : Ultimately switch to Locale.Builder for this. However, Locale.Builder is Java 7
|
||||||
String language = tokens.hasMoreTokens() ? tokens.nextToken() : "";
|
|
||||||
String country = tokens.hasMoreTokens() ? tokens.nextToken() : "";
|
final StringTokenizer tokens = new StringTokenizer( string, "_" );
|
||||||
// Need to account for allowable '_' within the variant
|
final String language = tokens.hasMoreTokens() && string.charAt(0) != '_' ? tokens.nextToken() : "";
|
||||||
|
final String country = tokens.hasMoreTokens() && string.charAt(string.indexOf(language) + language.length() + 1) != '_' ? tokens.nextToken() : "";
|
||||||
|
|
||||||
|
// Need to account for allowable '_' within the variant. The underscore within the variant delimits "subtags".
|
||||||
|
// Technically the reference spec (IETF BCP 47) also allows dash ("-") as a variant subtag delimiter.
|
||||||
|
// Note that this code block supports both approaches...
|
||||||
String variant = "";
|
String variant = "";
|
||||||
String sep = "";
|
String sep = "";
|
||||||
while ( tokens.hasMoreTokens() ) {
|
while ( tokens.hasMoreTokens() ) {
|
||||||
|
|
|
@ -42,15 +42,16 @@ import static org.junit.Assert.assertEquals;
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class LocaleTypeDescriptorTest extends BaseUnitTestCase {
|
public class LocaleTypeDescriptorTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConversionFromString() {
|
public void testConversionFromString() {
|
||||||
assertEquals( toLocale( "de", null, null ), LocaleTypeDescriptor.INSTANCE.fromString( "de" ) );
|
assertEquals( toLocale( "de", null, null ), LocaleTypeDescriptor.INSTANCE.fromString( "de" ) );
|
||||||
assertEquals( toLocale( "de", "DE", null ), LocaleTypeDescriptor.INSTANCE.fromString( "de_DE" ) );
|
assertEquals( toLocale( "de", "DE", null ), LocaleTypeDescriptor.INSTANCE.fromString( "de_DE" ) );
|
||||||
assertEquals( toLocale( null, "DE", null ), LocaleTypeDescriptor.INSTANCE.fromString( "_DE" ) );
|
assertEquals( toLocale( null, "DE", null ), LocaleTypeDescriptor.INSTANCE.fromString( "_DE" ) );
|
||||||
assertEquals( toLocale( null, null, "ch" ), LocaleTypeDescriptor.INSTANCE.fromString( "__ch" ) );
|
assertEquals( toLocale( null, null, "ch123" ), LocaleTypeDescriptor.INSTANCE.fromString( "__ch123" ) );
|
||||||
assertEquals( toLocale( null, "DE", "ch" ), LocaleTypeDescriptor.INSTANCE.fromString( "_DE_ch" ) );
|
assertEquals( toLocale( null, "DE", "ch123" ), LocaleTypeDescriptor.INSTANCE.fromString( "_DE_ch123" ) );
|
||||||
assertEquals( toLocale( "de", null, "ch" ), LocaleTypeDescriptor.INSTANCE.fromString( "de__ch" ) );
|
assertEquals( toLocale( "de", null, "ch123" ), LocaleTypeDescriptor.INSTANCE.fromString( "de__ch123" ) );
|
||||||
assertEquals( toLocale( "de", "DE", "ch" ), LocaleTypeDescriptor.INSTANCE.fromString( "de_DE_ch" ) );
|
assertEquals( toLocale( "de", "DE", "ch123" ), LocaleTypeDescriptor.INSTANCE.fromString( "de_DE_ch123" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public Locale toLocale(String lang, String region, String variant) {
|
public Locale toLocale(String lang, String region, String variant) {
|
||||||
|
|
Loading…
Reference in New Issue