Author: bayard Date: Thu Oct 24 20:54:34 2013 New Revision: 1535547 URL: http://svn.apache.org/r1535547 Log: Applying Thomas' patch from LANG-917 - fixing Arne Burmeister's reported exception when combining custom and choice formats
Modified: commons/proper/lang/trunk/src/changes/changes.xml commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/ExtendedMessageFormat.java commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java Modified: commons/proper/lang/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/changes/changes.xml?rev=1535547&r1=1535546&r2=1535547&view=diff ============================================================================== --- commons/proper/lang/trunk/src/changes/changes.xml (original) +++ commons/proper/lang/trunk/src/changes/changes.xml Thu Oct 24 20:54:34 2013 @@ -22,6 +22,7 @@ <body> <release version="3.2" date="TBA" description="Next release"> + <action issue="LANG-917" type="fix" due-to="Arne Burmeister">Fixed exception when combining custom and choice format in ExtendedMessageFormat</action> <action issue="LANG-848" type="add" due-to="Alexander Muthmann">Added StringUtils.isBlank/isEmpty CharSequence... methods</action> <action issue="LANG-926" type="add" dev="ggregory">Added ArrayUtils.reverse(array, from, to) methods</action> <action issue="LANG-795" type="add" due-to="Aaron Digulla">StringUtils.toString(byte[], String) deprecated in favour of a new StringUtils.toString(byte[], CharSet)</action> Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/ExtendedMessageFormat.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/ExtendedMessageFormat.java?rev=1535547&r1=1535546&r2=1535547&view=diff ============================================================================== --- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/ExtendedMessageFormat.java (original) +++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/ExtendedMessageFormat.java Thu Oct 24 20:54:34 2013 @@ -417,10 +417,10 @@ public class ExtendedMessageFormat exten break; case START_FE: depth++; + sb.append(START_FE).append(readArgumentIndex(pattern, next(pos))); + // do not look for custom patterns when they are embedded, e.g. in a choice if (depth == 1) { fe++; - sb.append(START_FE).append( - readArgumentIndex(pattern, next(pos))); final String customPattern = customPatterns.get(fe); if (customPattern != null) { sb.append(START_FMT).append(customPattern); Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java?rev=1535547&r1=1535546&r2=1535547&view=diff ============================================================================== --- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java (original) +++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java Thu Oct 24 20:54:34 2013 @@ -80,6 +80,16 @@ public class ExtendedMessageFormatTest { } /** + * Test Bug LANG-917 - IndexOutOfBoundsException and/or infinite loop when using a choice pattern + */ + @Test + public void testEmbeddedPatternInChoice() { + final String pattern = "Hi {0,lower}, got {1,choice,0#none|1#one|1<{1,number}}, {2,upper}!"; + final ExtendedMessageFormat emf = new ExtendedMessageFormat(pattern, registry); + assertEquals(emf.format(new Object[] {"there", 3, "great"}), "Hi there, got 3, GREAT!"); + } + + /** * Test extended and built in formats. */ @Test