Use locale-independent lowercasing in case conversion helpers#753
Use locale-independent lowercasing in case conversion helpers#753dxbjavid wants to merge 3 commits into
Conversation
garydgregory
left a comment
There was a problem hiding this comment.
@dxbjavid
You'll want to use JUnit Pioneer's annotations to manage the default Locale.
|
good point, done. switched both tests over to @DefaultLocale(language = "tr", country = "TR") and dropped the manual setDefault/finally dance, so pioneer handles save and restore now. tests still pass. |
| for (final String lookupName : str.split("[\\s,]+")) { | ||
| if (!lookupName.isEmpty()) { | ||
| addLookup(DefaultStringLookup.valueOf(lookupName.toUpperCase()), lookupMap); | ||
| addLookup(DefaultStringLookup.valueOf(lookupName.toUpperCase(Locale.ROOT)), lookupMap); |
There was a problem hiding this comment.
Hello @dxbjavid
This change is untested, either remove it or create a test for it.
TY
There was a problem hiding this comment.
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.
CaseUtils.toCamelCase and WordUtils.capitalizeFully fold their input to lower case with the no-arg String.toLowerCase(), so the output depends on the JVM default locale; under a Turkish locale an ASCII 'I' becomes the dotless 'ı' (U+0131), so capitalizeFully("HELI WORLD") comes back as "Helı World" rather than "Heli World" and toCamelCase("TIP.TOP", true, '.') yields "TıpTop". StringLookupFactory has the same issue when it upper-cases the default-lookups system property to match the enum names, which can stop a valid value like "file" from resolving on a Turkish JVM. I have switched all three sites to Locale.ROOT, matching the Locale.ROOT already used in StringLookupFactory.toKey, and added tests that pin the behaviour under a Turkish default locale.
mvn; that'smvnon the command line by itself.