Author: remy.maucherat(a)jboss.com
Date: 2008-04-17 15:23:46 -0400 (Thu, 17 Apr 2008)
New Revision: 586
Modified:
trunk/java/org/apache/catalina/ssi/SSIEcho.java
trunk/java/org/apache/catalina/ssi/SSIMediator.java
trunk/java/org/apache/catalina/ssi/SSIProcessor.java
trunk/webapps/docs/changelog.xml
Log:
- Port two Tomcat SSI patches.
Modified: trunk/java/org/apache/catalina/ssi/SSIEcho.java
===================================================================
--- trunk/java/org/apache/catalina/ssi/SSIEcho.java 2008-04-17 14:40:02 UTC (rev 585)
+++ trunk/java/org/apache/catalina/ssi/SSIEcho.java 2008-04-17 19:23:46 UTC (rev 586)
@@ -37,20 +37,14 @@
*/
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;
@@ -63,7 +57,13 @@
writer.write(errorMessage);
}
}
- return lastModified;
+ String variableValue = ssiMediator.getVariableValue(
+ originalValue, encoding);
+ if (variableValue == null) {
+ variableValue = MISSING_VARIABLE_VALUE;
+ }
+ writer.write(variableValue);
+ return System.currentTimeMillis();
}
@@ -72,4 +72,4 @@
|| encoding.equalsIgnoreCase("entity")
|| encoding.equalsIgnoreCase("none");
}
-}
\ No newline at end of file
+}
Modified: trunk/java/org/apache/catalina/ssi/SSIMediator.java
===================================================================
--- trunk/java/org/apache/catalina/ssi/SSIMediator.java 2008-04-17 14:40:02 UTC (rev 585)
+++ trunk/java/org/apache/catalina/ssi/SSIMediator.java 2008-04-17 19:23:46 UTC (rev 586)
@@ -27,6 +27,7 @@
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
@@ -205,10 +206,31 @@
* 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++) {
@@ -279,8 +301,7 @@
} 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);
@@ -328,4 +349,4 @@
retVal);
}
}
-}
\ No newline at end of file
+}
Modified: trunk/java/org/apache/catalina/ssi/SSIProcessor.java
===================================================================
--- trunk/java/org/apache/catalina/ssi/SSIProcessor.java 2008-04-17 14:40:02 UTC (rev
585)
+++ trunk/java/org/apache/catalina/ssi/SSIProcessor.java 2008-04-17 19:23:46 UTC (rev
586)
@@ -208,11 +208,10 @@
// Need to skip escaped characters
if (c == '\\' && !escaped) {
escaped = true;
- bIdx++;
continue;
}
+ if (c == '"' && !escaped) quotes++;
escaped = false;
- if (c == '"') quotes++;
}
}
}
@@ -322,4 +321,4 @@
protected boolean isQuote(char c) {
return c == '\'' || c == '\"' || c == '`';
}
-}
\ No newline at end of file
+}
Modified: trunk/webapps/docs/changelog.xml
===================================================================
--- trunk/webapps/docs/changelog.xml 2008-04-17 14:40:02 UTC (rev 585)
+++ trunk/webapps/docs/changelog.xml 2008-04-17 19:23:46 UTC (rev 586)
@@ -61,6 +61,12 @@
Better handling of lack of permission for context specific logging, and add
permission
for reading the JDK logging.properties. (markt)
</fix>
+ <fix>
+ <bug>44391</bug>: Correct handling of escaped values in SSI
processing. (markt)
+ </fix>
+ <fix>
+ <bug>44392</bug>: HTML entities now handled correctly in SSI
processing. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">
Show replies by date