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-text.git
The following commit(s) were added to refs/heads/master by this push:
new 85f4b3c5 Throw IllegalArgumentException for trailing whitespace in
extendedmessageformat argument index (#750)
85f4b3c5 is described below
commit 85f4b3c5736231e14e517d110f4314965221a8d1
Author: Javid Khan <[email protected]>
AuthorDate: Fri Jun 12 07:34:40 2026 +0530
Throw IllegalArgumentException for trailing whitespace in
extendedmessageformat argument index (#750)
---
src/main/java/org/apache/commons/text/ExtendedMessageFormat.java | 3 +++
src/test/java/org/apache/commons/text/ExtendedMessageFormatTest.java | 5 +++++
2 files changed, 8 insertions(+)
diff --git a/src/main/java/org/apache/commons/text/ExtendedMessageFormat.java
b/src/main/java/org/apache/commons/text/ExtendedMessageFormat.java
index 4dcd957f..d0581390 100644
--- a/src/main/java/org/apache/commons/text/ExtendedMessageFormat.java
+++ b/src/main/java/org/apache/commons/text/ExtendedMessageFormat.java
@@ -442,6 +442,9 @@ public class ExtendedMessageFormat extends MessageFormat {
char c = pattern.charAt(pos.getIndex());
if (Character.isWhitespace(c)) {
seekNonWs(pattern, pos);
+ if (pos.getIndex() >= pattern.length()) {
+ break;
+ }
c = pattern.charAt(pos.getIndex());
if (c != START_FMT && c != END_FE) {
error = true;
diff --git
a/src/test/java/org/apache/commons/text/ExtendedMessageFormatTest.java
b/src/test/java/org/apache/commons/text/ExtendedMessageFormatTest.java
index 71483376..530b0ccb 100644
--- a/src/test/java/org/apache/commons/text/ExtendedMessageFormatTest.java
+++ b/src/test/java/org/apache/commons/text/ExtendedMessageFormatTest.java
@@ -474,6 +474,11 @@ class ExtendedMessageFormatTest {
assertThrowsExactly(IllegalArgumentException.class, () -> new
ExtendedMessageFormat("a5XdkR;T1{9 ,LzXf?", new HashMap<>()));
}
+ @Test
+ void testArgumentIndexTrailingWhitespaceAtEnd() {
+ assertThrowsExactly(IllegalArgumentException.class, () -> new
ExtendedMessageFormat("{0 ", new HashMap<>()));
+ }
+
@Test
void testOverriddenBuiltinFormat() {
final Calendar cal = Calendar.getInstance();