IllegalStateException in text.VariableFormatter with "empty" keys.

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@225179 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary D. Gregory 2005-07-25 20:52:08 +00:00
parent d1f1606960
commit abbe3f0e26
2 changed files with 16 additions and 21 deletions

View File

@ -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;

View File

@ -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);
}
/**