Skip to content

StringUtils.parseLocaleString: locale variant cannot contain country code [SPR-11806] #16426

@spring-projects-issues

Description

@spring-projects-issues

John Olmstead opened SPR-11806 and commented

The StringUtils.parseLocaleString method fails to correctly parse the variant if the variant contains the same characters as the country code. This is due to the fact that the lastIndexOf the country code is used as the dividing point instead of the first indexOf.

Here is the test to add to org.springframework.util.StringUtilsTest:

public void testParseLocaleWithVarientContainingCountryCode() throws Exception {
    final String variant = "GBtest";
    final String localeString = "en_GB_" + variant;
    Locale locale = StringUtils.parseLocaleString(localeString);
    assertEquals("Variant containing country code not extracted correctly.", variant, locale.getVariant());
}

Affects: 3.2.8, 4.0.4

Backported to: 3.2.9

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions