diff --git a/src/changes/changes.xml b/src/changes/changes.xml index b023f95c0..13e83b41c 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -76,6 +76,7 @@ The type attribute can be add,update,fix,remove. Add SystemUtils.getHostName() API. Moving apache-rat-plugin configuration into pluginManagement TypeUtils.toString() doesn't handle primitive and Object arrays correctly + LocaleUtils#toLocale does not support language followed by UN M.49 numeric-3 area code diff --git a/src/main/java/org/apache/commons/lang3/LocaleUtils.java b/src/main/java/org/apache/commons/lang3/LocaleUtils.java index a3126ebf4..f13b52f38 100644 --- a/src/main/java/org/apache/commons/lang3/LocaleUtils.java +++ b/src/main/java/org/apache/commons/lang3/LocaleUtils.java @@ -67,6 +67,7 @@ public class LocaleUtils { * LocaleUtils.toLocale("") = new Locale("", "") * LocaleUtils.toLocale("en") = new Locale("en", "") * LocaleUtils.toLocale("en_GB") = new Locale("en", "GB") + * LocaleUtils.toLocale("en_001") = new Locale("en", "001") * LocaleUtils.toLocale("en_GB_xxx") = new Locale("en", "GB", "xxx") (#) * * @@ -134,7 +135,8 @@ public class LocaleUtils { case 1: if (StringUtils.isAllLowerCase(split[0]) && (split[0].length() == 2 || split[0].length() == 3) && - split[1].length() == 2 && StringUtils.isAllUpperCase(split[1])) { + (split[1].length() == 2 && StringUtils.isAllUpperCase(split[1])) || + (split[1].length() == 3 && StringUtils.isNumeric(split[1]))) { return new Locale(split[0], split[1]); } throw new IllegalArgumentException("Invalid locale format: " + str); diff --git a/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java b/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java index 4a867bab1..79198af5b 100644 --- a/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java @@ -505,6 +505,13 @@ public class LocaleUtilsTest { assertValidToLocale("fr__POSIX", "fr", "", "POSIX"); } + @Test + public void testLanguageAndUNM49Numeric3AreaCodeLang1312() { + assertValidToLocale("en_001", "en", "001"); + assertValidToLocale("en_150", "en", "150"); + assertValidToLocale("ar_001", "ar", "001"); + } + /** * Tests #LANG-865, strings starting with an underscore. */