Description
The replace method in the org.apache.cactus.internal.server.runner.XMLFormatter might cut off characters...
Example:
replace("12x456x89", 'x', "<X>")
Will return 12<X>456<X>
This method can even produce an infinite loop, if the char that is searched for is included in the result String.
replace("12x456x890", 'x', "<x>")
But that should not be the case within cactus.
Also the performance of this method is really bad, because String concatenations are used. A StringBuffer used to produce the result would be better.
Here is my suggestion for a replacement....
private static String replace(String theBaseString, char theChar,
String theNewString) {
if (theBaseString == null)
{ return null; } int pos = theBaseString.indexOf(theChar);
if (pos < 0) return theBaseString;
int lastPos = 0;
StringBuffer result = new StringBuffer();
while (pos > -1)
if (lastPos < theBaseString.length())
result.append(theBaseString.substring(lastPos));
return result.toString();
}