From a38e2e942d622c1a84ed35bedb9aba045db7ab79 Mon Sep 17 00:00:00 2001 From: Niall Pemberton Date: Fri, 9 Jan 2009 22:05:14 +0000 Subject: [PATCH] Fix for LANG-477 OutOfMemory with custom format registry and a pattern containing single quotes - thanks to Duncan Eley git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@733169 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/commons/lang/text/ExtendedMessageFormat.java | 1 + .../commons/lang/text/ExtendedMessageFormatTest.java | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/src/java/org/apache/commons/lang/text/ExtendedMessageFormat.java b/src/java/org/apache/commons/lang/text/ExtendedMessageFormat.java index 404be490c..4af3955b5 100644 --- a/src/java/org/apache/commons/lang/text/ExtendedMessageFormat.java +++ b/src/java/org/apache/commons/lang/text/ExtendedMessageFormat.java @@ -419,6 +419,7 @@ public class ExtendedMessageFormat extends MessageFormat { int start = pos.getIndex(); char[] c = pattern.toCharArray(); if (escapingOn && c[start] == QUOTE) { + next(pos); return appendTo == null ? null : appendTo.append(QUOTE); } int lastHold = start; diff --git a/src/test/org/apache/commons/lang/text/ExtendedMessageFormatTest.java b/src/test/org/apache/commons/lang/text/ExtendedMessageFormatTest.java index 8a90abb14..53827ae8c 100644 --- a/src/test/org/apache/commons/lang/text/ExtendedMessageFormatTest.java +++ b/src/test/org/apache/commons/lang/text/ExtendedMessageFormatTest.java @@ -92,6 +92,15 @@ public class ExtendedMessageFormatTest extends TestCase { assertEquals("Lower: foo Upper: BAR", emf.format(new Object[] {"foo", "BAR"})); } + /** + * Test Bug LANG-477 - out of memory error with escaped quote + */ + public void testEscapedQuote_LANG_477() { + String pattern = "it''s a {0,lower} 'test'!"; + ExtendedMessageFormat emf = new ExtendedMessageFormat(pattern, registry); + assertEquals("it's a dummy test!", emf.format(new Object[] {"DUMMY"})); + } + /** * Test extended and built in formats. */