Skip to content

Commit 81c2140

Browse files
Mert ÇALIŞKANgsmet
Mert ÇALIŞKAN
authored andcommitted
HV-1140 Use ROOT locale in StringHelper#decapitalize
Before that, we could have locale specific behaviors when lowercasing. It was especially true for the Turkish locale - which is often cited as an example of this issue.
1 parent 39c7b9f commit 81c2140

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

engine/src/main/java/org/hibernate/validator/internal/util/StringHelper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package org.hibernate.validator.internal.util;
88

99
import java.util.Arrays;
10+
import java.util.Locale;
1011

1112
/**
1213
* Helper class dealing with strings.
@@ -81,7 +82,7 @@ public static String decapitalize(String string) {
8182
return string;
8283
}
8384
else {
84-
return string.substring( 0, 1 ).toLowerCase() + string.substring( 1 );
85+
return string.substring( 0, 1 ).toLowerCase( Locale.ROOT ) + string.substring( 1 );
8586
}
8687
}
8788

engine/src/test/java/org/hibernate/validator/test/internal/util/StringHelperTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
package org.hibernate.validator.test.internal.util;
88

99
import java.util.Arrays;
10+
import java.util.Locale;
1011

12+
import org.hibernate.validator.testutil.TestForIssue;
1113
import org.testng.annotations.Test;
1214

1315
import org.hibernate.validator.internal.util.StringHelper;
@@ -87,6 +89,15 @@ public void decapitalizeShouldReturnDecapizalizedWord() {
8789
assertEquals( StringHelper.decapitalize( "Giraffe" ), "giraffe" );
8890
}
8991

92+
@Test
93+
@TestForIssue(jiraKey = "HV-1140")
94+
public void decapitalizeShouldReturnDecapizalizedWordOnTurkishLocale() {
95+
Locale defaultLocale = Locale.getDefault();
96+
Locale.setDefault( new Locale( "tr" , "TR" ) );
97+
assertEquals( StringHelper.decapitalize( "IsIsolationLevelGuaranteed" ), "isIsolationLevelGuaranteed" );
98+
Locale.setDefault( defaultLocale );
99+
}
100+
90101
@Test
91102
public void decapitalizeShouldReturnSameWordForDecapizalizedWord() {
92103
assertEquals( StringHelper.decapitalize( "giraffe" ), "giraffe" );

0 commit comments

Comments
 (0)