-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Closed
Closed
Copy link
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently applyA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancementA general enhancement
Description
Cédrik LIME opened SPR-6562 and commented
StringUtils#parseLocaleString(String) is supposed to be the exact inverse operation to Locale.toString().
This is not the case for new Locale("", "", ""), which String representation is "", but which comes back as null from StringUtils.parseLocaleString("").
The parseLocaleString() method should be:
public static Locale parseLocaleString(String localeString) {
if (localeString == null) {
return null;
}
String[] parts = tokenizeToStringArray(localeString, "_ ", false, false);
String language = (parts.length > 0 ? parts[0] : "");
String country = (parts.length > 1 ? parts[1] : "");
String variant = "";
if (parts.length >= 2) {
// There is definitely a variant, and it is everything after the country
// code sans the separator between the country code and the variant.
int endIndexOfCountryCode = localeString.indexOf(country) + country.length();
// Strip off any leading '_' and whitespace, what's left is the variant.
variant = trimLeadingWhitespace(localeString.substring(endIndexOfCountryCode));
if (variant.startsWith("_")) {
variant = trimLeadingCharacter(variant, '_');
}
}
return new Locale(language, country, variant);
}
Affects: 2.5.6
Issue Links:
- LocaleEditor does not work with some locale strings [SPR-8099] #12754 LocaleEditor does not work with some locale strings
- Revise StringUtils.parseLocale(String) for proper handling of corner cases [SPR-16651] #21192 Revise StringUtils.parseLocale(String) for proper handling of corner cases
- StringUtils#parseLocaleString(String) with Variant when no Country [SPR-7598] #12254 StringUtils#parseLocaleString(String) with Variant when no Country ("is superseded by")
1 votes, 3 watchers
Metadata
Metadata
Assignees
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently applyA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancementA general enhancement