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 8425918f9 Keep ExtendedMessageFormat from rejecting a quoted format
style (#1744)
8425918f9 is described below
commit 8425918f90e8c3c6e39f14e18335ecb8e4589b91
Author: alhuda <[email protected]>
AuthorDate: Tue Jul 7 16:04:19 2026 +0530
Keep ExtendedMessageFormat from rejecting a quoted format style (#1744)
---
.../apache/commons/lang3/text/ExtendedMessageFormat.java | 5 ++++-
.../commons/lang3/text/ExtendedMessageFormatTest.java | 13 +++++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git
a/src/main/java/org/apache/commons/lang3/text/ExtendedMessageFormat.java
b/src/main/java/org/apache/commons/lang3/text/ExtendedMessageFormat.java
index 353303bdc..e2cde7207 100644
--- a/src/main/java/org/apache/commons/lang3/text/ExtendedMessageFormat.java
+++ b/src/main/java/org/apache/commons/lang3/text/ExtendedMessageFormat.java
@@ -382,21 +382,24 @@ private String parseFormatDescription(final String
pattern, final ParsePosition
seekNonWs(pattern, pos);
final int text = pos.getIndex();
int depth = 1;
- for (; pos.getIndex() < pattern.length(); next(pos)) {
+ while (pos.getIndex() < pattern.length()) {
switch (pattern.charAt(pos.getIndex())) {
case START_FE:
depth++;
+ next(pos);
break;
case END_FE:
depth--;
if (depth == 0) {
return pattern.substring(text, pos.getIndex());
}
+ next(pos);
break;
case QUOTE:
getQuotedString(pattern, pos);
break;
default:
+ next(pos);
break;
}
}
diff --git
a/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java
b/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java
index 630f7e326..c5f6b90f3 100644
--- a/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java
+++ b/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java
@@ -344,6 +344,19 @@ void testEmbeddedPatternInChoice() {
assertEquals(emf.format(new Object[] {"there", 3, "great"}), "Hi
there, got 3, GREAT!");
}
+ /**
+ * A format element whose format style ends with a quoted literal
immediately before the closing brace is a valid
+ * pattern (accepted by {@link MessageFormat} and by this class when no
registry is supplied), but the registry
+ * parsing path rejected it with "Unterminated format element".
+ */
+ @Test
+ void testQuotedLiteralAtEndOfFormatElement() {
+ assertEquals("ABC", new ExtendedMessageFormat("{0,upper,'x'}",
registry).format(new Object[] {"abc"}));
+ assertEquals("ABC", new ExtendedMessageFormat("{0,upper,'}'}",
registry).format(new Object[] {"abc"}));
+ // a built-in format style ending in a quote only reaches the registry
parser because the registry is non-null
+ assertEquals("5%", new ExtendedMessageFormat("{0,number,0'%'}",
registry).format(new Object[] {Integer.valueOf(5)}));
+ }
+
/**
* Test equals() and hashCode().
*/