Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern;

import org.springframework.util.Assert;
Expand All @@ -27,6 +28,7 @@
* Utility methods for {@link String} parsing.
*
* @author Oliver Gierke
* @author Sharang Gupta
* @since 1.5
*/
public abstract class ParsingUtils {
Expand Down Expand Up @@ -84,7 +86,9 @@ private static List<String> split(String source, boolean toLower) {
List<String> result = new ArrayList<>(parts.length);

for (String part : parts) {
result.add(toLower ? part.toLowerCase() : part);
// Locale.ROOT: the parts become identifiers (table, column and field names) and must not follow the default
// locale, under which e.g. "Item" would become "ıtem" (dotless i) for tr-TR.
result.add(toLower ? part.toLowerCase(Locale.ROOT) : part);
}

return Collections.unmodifiableList(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@

import static org.assertj.core.api.Assertions.*;

import java.util.Locale;

import org.junit.jupiter.api.Test;

/**
* Unit tests for {@link ParsingUtils}.
*
* @author Oliver Gierke
* @author Sharang Gupta
*/
public class ParsingUtilsUnitTests {

Expand Down Expand Up @@ -50,4 +53,18 @@ public void splitsCamelCaseWithAllSortsOfCharacters() {
public void reconcatenatesCamelCaseString() {
assertThat(ParsingUtils.reconcatenateCamelCase("myCamelCase", "-")).isEqualTo("my-camel-case");
}

@Test
public void lowercasesPartsRegardlessOfDefaultLocale() {

var defaultLocale = Locale.getDefault();
Locale.setDefault(Locale.forLanguageTag("tr-TR"));

try {
assertThat(ParsingUtils.reconcatenateCamelCase("InvoiceItem", "_")).isEqualTo("invoice_item");
assertThat(ParsingUtils.splitCamelCaseToLower("invoiceId")).containsExactly("invoice", "id");
} finally {
Locale.setDefault(defaultLocale);
}
}
}
Loading