*/
public long process(SSIMediator ssiMediator, String commandName,
String[] paramNames, String[] paramValues, PrintWriter writer) {
- long lastModified = 0;
String encoding = DEFAULT_ENCODING;
+ String originalValue = null;
String errorMessage = ssiMediator.getConfigErrMsg();
for (int i = 0; i < paramNames.length; i++) {
String paramName = paramNames[i];
String paramValue = paramValues[i];
if (paramName.equalsIgnoreCase("var")) {
- String variableValue = ssiMediator.getVariableValue(
- paramValue, encoding);
- if (variableValue == null) {
- variableValue = MISSING_VARIABLE_VALUE;
- }
- writer.write(variableValue);
- lastModified = System.currentTimeMillis();
+ originalValue = paramValue;
} else if (paramName.equalsIgnoreCase("encoding")) {
if (isValidEncoding(paramValue)) {
encoding = paramValue;
writer.write(errorMessage);
}
}
- return lastModified;
+ String variableValue = ssiMediator.getVariableValue(
+ originalValue, encoding);
+ if (variableValue == null) {
+ variableValue = MISSING_VARIABLE_VALUE;
+ }
+ writer.write(variableValue);
+ return System.currentTimeMillis();
}
import org.apache.catalina.util.DateTool;
import org.apache.catalina.util.Strftime;
import org.apache.catalina.util.URLEncoder;
+import org.apache.tomcat.util.http.HttpMessages;
/**
* Allows the different SSICommand implementations to share data/talk to each
* other
* new resolved string.
*/
public String substituteVariables(String val) {
- // If it has no variable references then no work
+ // If it has no references or HTML entities then no work
// need to be done
- if (val.indexOf('$') < 0) return val;
+ if (val.indexOf('$') < 0 && val.indexOf('&') < 0) return val;
+
+ // HTML decoding
+ val.replace("<", "<");
+ val.replace(">", ">");
+ val.replace(""", "\"");
+ val.replace("&", "&");
+
StringBuffer sb = new StringBuffer(val);
+ int charStart = sb.indexOf("&#");
+ while (charStart > -1) {
+ int charEnd = sb.indexOf(";", charStart);
+ if (charEnd > -1) {
+ char c = (char) Integer.parseInt(
+ sb.substring(charStart + 2, charEnd));
+ sb.delete(charStart, charEnd + 1);
+ sb.insert(charStart, c);
+ charStart = sb.indexOf("&#");
+ } else {
+ break;
+ }
+ }
+
for (int i = 0; i < sb.length();) {
// Find the next $
for (; i < sb.length(); i++) {
} else if (encoding.equalsIgnoreCase("none")) {
retVal = value;
} else if (encoding.equalsIgnoreCase("entity")) {
- //Not sure how this is really different than none
- retVal = value;
+ retVal = HttpMessages.filter(value);
} else {
//This shouldn't be possible
throw new IllegalArgumentException("Unknown encoding: " + encoding);