diff --git a/src/java/org/apache/commons/lang/text/VariableFormatter.java b/src/java/org/apache/commons/lang/text/VariableFormatter.java index a069fad92..3bb0e9dbf 100644 --- a/src/java/org/apache/commons/lang/text/VariableFormatter.java +++ b/src/java/org/apache/commons/lang/text/VariableFormatter.java @@ -390,16 +390,16 @@ private Object doReplace(Object obj, List priorVariables) { objResult = doReplace(objResult, priorVariables); result.append(objResult); objLen = objResult.toString().length(); - - // pop the interpolated variable off the stack - // this maintains priorVariables correctness for - // properties with multiple interpolations, e.g. - // prop.name=${some.other.prop1}/blahblah/${some.other.prop2} - priorVariables.remove(priorVariables.size() - 1); } else { // variable not defined - so put it back in the value result.append(getVariablePrefix()).append(variable).append(getVariableSuffix()); } + + // pop the interpolated variable off the stack + // this maintains priorVariables correctness for + // properties with multiple interpolations, e.g. + // prop.name=${some.other.prop1}/blahblah/${some.other.prop2} + priorVariables.remove(priorVariables.size() - 1); } prec = end; diff --git a/src/test/org/apache/commons/lang/text/VariableFormatterTest.java b/src/test/org/apache/commons/lang/text/VariableFormatterTest.java index c101ebe18..268955009 100644 --- a/src/test/org/apache/commons/lang/text/VariableFormatterTest.java +++ b/src/test/org/apache/commons/lang/text/VariableFormatterTest.java @@ -226,6 +226,13 @@ public void testReplace() { assertEquals("Variable ${var} is unknown!", this.getFormat().replace("Variable ${var} is unknown!")); } + /** + * Tests a replace template with missing empty marker strings. + */ + public void testReplaceEmptyKeys() { + testReplaceNoElement(REPLACE_TEMPLATE_EMPTY_KEYS); + } + void testReplaceNoElement(String badReplaceTemplate) { assertEquals(badReplaceTemplate, this.getFormat().replaceObject(badReplaceTemplate)); Map map = this.getValueMap(); @@ -242,13 +249,6 @@ public void testReplaceNoEscape() { testReplaceNoElement(REPLACE_TEMPLATE_NO_ESCAPE); } - /** - * Tests a replace template with missing prefix strings. - */ - public void testReplaceNoPrefix() { - testReplaceNoElement(REPLACE_TEMPLATE_NO_PREFIX); - } - /** * Tests a replace template with missing marker strings. */ @@ -257,15 +257,10 @@ public void testReplaceNoMarkers() { } /** - * Tests a replace template with missing empty marker strings. + * Tests a replace template with missing prefix strings. */ - public void testReplaceEmptyKeys() { - try { - testReplaceNoElement(REPLACE_TEMPLATE_EMPTY_KEYS); - fail("Expected IllegalStateException."); - } catch (IllegalStateException e) { - // expected for now. - } + public void testReplaceNoPrefix() { + testReplaceNoElement(REPLACE_TEMPLATE_NO_PREFIX); } /**