From 4fa3c67db4663642f7e971f05a5ca6125790ce99 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 18 May 2026 17:30:07 -0400 Subject: [PATCH] FormattableUtils.append re-parses literal output as format string --- .../java/org/apache/commons/text/FormattableUtils.java | 3 +-- .../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 f0be6ddb8d..0506e12c76 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 static Formatter append(final CharSequence seq, final Formatter formatter 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 36ab8b5066..11d6177d9e 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 @@ void testIllegalEllipsisWith7Args() { () -> 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();