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 ac2c6604 FormattableUtils.append re-parses literal output as format 
string (#743)
ac2c6604 is described below

commit ac2c660488c81e36edfc91e4d1b400b130701401
Author: Gary Gregory <[email protected]>
AuthorDate: Mon May 18 18:29:26 2026 -0400

    FormattableUtils.append re-parses literal output as format string (#743)
---
 src/main/java/org/apache/commons/text/FormattableUtils.java    |  3 +--
 .../java/org/apache/commons/text/FormattableUtilsTest.java     | 10 ++++++++++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/commons/text/FormattableUtils.java 
b/src/main/java/org/apache/commons/text/FormattableUtils.java
index f0be6ddb..0506e12c 100644
--- a/src/main/java/org/apache/commons/text/FormattableUtils.java
+++ b/src/main/java/org/apache/commons/text/FormattableUtils.java
@@ -107,8 +107,7 @@ public class FormattableUtils {
         for (int i = buf.length(); i < width; i++) {
             buf.insert(leftJustify ? i : 0, padChar);
         }
-        formatter.format(buf.toString());
-        return formatter;
+        return formatter.format(SIMPLEST_FORMAT, buf.toString());
     }
 
     /**
diff --git a/src/test/java/org/apache/commons/text/FormattableUtilsTest.java 
b/src/test/java/org/apache/commons/text/FormattableUtilsTest.java
index 36ab8b50..11d6177d 100644
--- a/src/test/java/org/apache/commons/text/FormattableUtilsTest.java
+++ b/src/test/java/org/apache/commons/text/FormattableUtilsTest.java
@@ -144,6 +144,16 @@ class FormattableUtilsTest {
                 () -> FormattableUtils.append("foo", createFormatter(), 0, 0, 
precisionLessThanEllipsisLength, '}', ellipsis));
     }
 
+    @Test
+    void testPercentLiteral() {
+        assertEquals("100% done", FormattableUtils.append("100% done", new 
Formatter(), 0, -1, -1).toString());
+    }
+
+    @Test
+    void testPercentLiteralX2() {
+        assertEquals("50% off 100% items", FormattableUtils.append("50% off 
100% items", new Formatter(), 0, -1, -1).toString());
+    }
+
     @Test
     void testPublicConstructorExists() {
         new FormattableUtils();

Reply via email to