*/
protected String replace(String str) {
String result = str;
- int pos_start = result.indexOf("${");
- if (pos_start != -1) {
- int pos_end = result.indexOf('}', pos_start);
- if (pos_end != -1) {
- String propName = result.substring(pos_start + 2, pos_end);
- String replacement = System.getProperty(propName);
+ int pos_start = str.indexOf("${");
+ if (pos_start >= 0) {
+ StringBuilder builder = new StringBuilder();
+ int pos_end = -1;
+ while (pos_start >= 0) {
+ builder.append(str, pos_end + 1, pos_start);
+ pos_end = str.indexOf('}', pos_start + 2);
+ if (pos_end < 0) {
+ pos_end = pos_start - 1;
+ break;
+ }
+ String propName = str.substring(pos_start + 2, pos_end);
+ String replacement = propName.length() > 0 ? System
+ .getProperty(propName) : null;
if (replacement != null) {
- if(pos_start >0) {
- result = result.substring(0,pos_start) +
- replacement + replace(result.substring(pos_end + 1));
- } else {
- result = replacement + replace(result.substring(pos_end + 1));
- }
+ builder.append(replacement);
+ } else {
+ builder.append(str, pos_start, pos_end + 1);
}
+ pos_start = str.indexOf("${", pos_end + 1);
}
+ builder.append(str, pos_end + 1, str.length());
+ result = builder.toString();
}
return result;
}
-
// ---------------------------------------------------- LogNode Inner Class
ClassLoaderLogManager logManager = new ClassLoaderLogManager();
assertEquals("", logManager.replace(""));
assertEquals("${", logManager.replace("${"));
- assertEquals("${undefinedsystemproperty}",
- logManager.replace("${undefinedsystemproperty}"));
+ assertEquals("${undefinedproperty}",
+ logManager.replace("${undefinedproperty}"));
assertEquals(
System.getProperty("line.separator")
+ System.getProperty("path.separator")
assertEquals(
"%{file.separator}" + System.getProperty("file.separator"),
logManager.replace("%{file.separator}${file.separator}"));
+ assertEquals(
+ System.getProperty("file.separator") + "${undefinedproperty}"
+ + System.getProperty("file.separator"),
+ logManager
+ .replace("${file.separator}${undefinedproperty}${file.separator}"));
+ assertEquals("${}" + System.getProperty("path.separator"),
+ logManager.replace("${}${path.separator}"));
}
}
files in parallel. Apache Tomcat does not do this but products that
embed it may. (markt)
</fix>
+ <fix>
+ <bug>51249</bug>: Further improve system property replacement code
+ in ClassLoaderLogManager of Tomcat JULI to cover some corner cases.
+ (kkolinko)
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">
</fix>
<fix>
<bug>51249</bug>: Correct ClassLoaderLogManager system property
- replacement code so properties of the form ${...}${...} can be used
+ replacement code so properties of the form "}${...}" can be used
without error. (markt)
</fix>
<fix>