Applying Thomas' patch from LANG-917 - fixing Arne Burmeister's reported exception when combining custom and choice formats

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1535547 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2013-10-24 20:54:34 +00:00
parent a93703d002
commit be370cd0ef
3 changed files with 13 additions and 2 deletions

View File

@ -22,6 +22,7 @@
<body> <body>
<release version="3.2" date="TBA" description="Next release"> <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-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-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> <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>

View File

@ -417,10 +417,10 @@ private String insertFormats(final String pattern, final ArrayList<String> custo
break; break;
case START_FE: case START_FE:
depth++; 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) { if (depth == 1) {
fe++; fe++;
sb.append(START_FE).append(
readArgumentIndex(pattern, next(pos)));
final String customPattern = customPatterns.get(fe); final String customPattern = customPatterns.get(fe);
if (customPattern != null) { if (customPattern != null) {
sb.append(START_FMT).append(customPattern); sb.append(START_FMT).append(customPattern);

View File

@ -79,6 +79,16 @@ public void testEscapedQuote_LANG_477() {
assertEquals("it's a dummy test!", emf.format(new Object[] {"DUMMY"})); assertEquals("it's a dummy test!", emf.format(new Object[] {"DUMMY"}));
} }
/**
* 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 extended and built in formats.
*/ */