This is an automated email from the ASF dual-hosted git repository.
garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
The following commit(s) were added to refs/heads/master by this push:
new 0b4a9d95d LocaleUtils.parseLocale(String) operator precedence bug
allows invalid language with numeric country (#1658)
0b4a9d95d is described below
commit 0b4a9d95df610bfcc83c375110ac100d08662ba1
Author: Gary Gregory <[email protected]>
AuthorDate: Mon May 18 09:23:45 2026 -0400
LocaleUtils.parseLocale(String) operator precedence bug allows invalid
language with numeric country (#1658)
---
src/main/java/org/apache/commons/lang3/LocaleUtils.java | 2 +-
src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java | 10 ++++++++++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/apache/commons/lang3/LocaleUtils.java
b/src/main/java/org/apache/commons/lang3/LocaleUtils.java
index ea075cb5b..4a5821dad 100644
--- a/src/main/java/org/apache/commons/lang3/LocaleUtils.java
+++ b/src/main/java/org/apache/commons/lang3/LocaleUtils.java
@@ -338,7 +338,7 @@ private static Locale parseLocale(final String str) {
final String language = segments[0];
if (segments.length == 2) {
final String country = segments[1];
- if (isISO639LanguageCode(language) &&
isISO3166CountryCode(country) || isNumericAreaCode(country)) {
+ if (isISO639LanguageCode(language) &&
(isISO3166CountryCode(country) || isNumericAreaCode(country))) {
return new Locale(language, country);
}
} else if (segments.length == limit) {
diff --git a/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java
b/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java
index 9fcbabcf7..4adadb4cd 100644
--- a/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java
@@ -256,6 +256,16 @@ void testCountriesByLanguage() {
assertCountriesByLanguage("it", new String[]{"IT", "CH"});
}
+ @Test
+ void testIllegalLanguageWithNumericCountry() {
+ assertIllegalArgumentException(() ->
LocaleUtils.toLocale("../../unexpected_001"));
+ }
+
+ @Test
+ void testIllegalSingleCharLanguageWithNumericCountry() {
+ assertIllegalArgumentException(() -> LocaleUtils.toLocale("x_001"));
+ }
+
/**
* Test availableLocaleSet() method.
*/