Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/java/org/apache/commons/text/CaseUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.commons.text;

import java.util.HashSet;
import java.util.Locale;
import java.util.Set;

import org.apache.commons.lang3.ArrayUtils;
Expand Down Expand Up @@ -70,7 +71,7 @@ public static String toCamelCase(String str, final boolean capitalizeFirstLetter
if (StringUtils.isEmpty(str)) {
return str;
}
str = str.toLowerCase();
str = str.toLowerCase(Locale.ROOT);
final int strLen = str.length();
final int[] newCodePoints = new int[strLen];
int outOffset = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/apache/commons/text/WordUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.commons.text;

import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import java.util.function.Predicate;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -250,7 +251,7 @@ public static String capitalizeFully(String str, final char... delimiters) {
if (StringUtils.isEmpty(str)) {
return str;
}
str = str.toLowerCase();
str = str.toLowerCase(Locale.ROOT);
return capitalize(str, delimiters);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ private static Map<String, StringLookup> parseStringLookups(final String str) {
try {
for (final String lookupName : str.split("[\\s,]+")) {
if (!lookupName.isEmpty()) {
addLookup(DefaultStringLookup.valueOf(lookupName.toUpperCase()), lookupMap);
addLookup(DefaultStringLookup.valueOf(lookupName.toUpperCase(Locale.ROOT)), lookupMap);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @dxbjavid
This change is untested, either remove it or create a test for it.
TY

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a test for it. testDefaultStringLookupsHolder_givenSingleLookup_localeIndependent feeds a lowercase "file" through the holder under a tr-TR default locale; without Locale.ROOT the upper-case folds the i to dotted İ and valueOf throws, so the test fails on the unpatched code and passes with the fix.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, ty.

}
}
} catch (final IllegalArgumentException exc) {
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/org/apache/commons/text/CaseUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.util.Locale;

import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -77,4 +78,17 @@ void testToCamelCase() {
assertEquals("\uD800\uDF00\uD800\uDF01\uD800\uDF02\uD800\uDF03",
CaseUtils.toCamelCase("\uD800\uDF00\uD800\uDF01\uD800\uDF14\uD800\uDF02\uD800\uDF03", true, '\uD800', '\uDF14'));
}

@Test
void testToCamelCaseLocaleIndependent() {
final Locale dflt = Locale.getDefault();
try {
// Turkish lower-cases 'I' (U+0049) to dotless 'i' (U+0131), which would otherwise leak into the result.
Locale.setDefault(new Locale("tr", "TR"));
assertEquals("TipTop", CaseUtils.toCamelCase("TIP.TOP", true, '.'));
assertEquals("toCamelCase", CaseUtils.toCamelCase("TO CAMEL CASE", false, null));
} finally {
Locale.setDefault(dflt);
}
}
}
14 changes: 14 additions & 0 deletions src/test/java/org/apache/commons/text/WordUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.time.Duration;
import java.util.Locale;
import java.util.stream.IntStream;

import org.apache.commons.lang3.ArrayUtils;
Expand Down Expand Up @@ -124,6 +125,19 @@ void testCapitalizeFully_String() {

}

@Test
void testCapitalizeFully_LocaleIndependent() {
final Locale dflt = Locale.getDefault();
try {
// Turkish lower-cases 'I' (U+0049) to dotless 'i' (U+0131), which would otherwise leak into the result.
Locale.setDefault(new Locale("tr", "TR"));
assertEquals("Heli World", WordUtils.capitalizeFully("HELI WORLD"));
assertEquals("I Am Here 123", WordUtils.capitalizeFully("I AM HERE 123"));
} finally {
Locale.setDefault(dflt);
}
}

@Test
void testCapitalizeFully_Text88() {
assertEquals("I am fine now", WordUtils.capitalizeFully("i am fine now", new char[] {}));
Expand Down