You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by sc...@apache.org on 2012/03/06 23:08:57 UTC
svn commit: r1297754 - in /velocity/tools/branches/2.0.x:
src/main/java/org/apache/velocity/tools/struts/ValidatorTool.java
xdocs/changes.xml
Author: schultz
Date: Tue Mar 6 22:08:57 2012
New Revision: 1297754
URL: http://svn.apache.org/viewvc?rev=1297754&view=rev
Log:
Fixed VELTOOLS-152: ValidatorTool generates invalid XHTML even when in XHTML mode
- Added extra escaping when in XHTML mode
Modified:
velocity/tools/branches/2.0.x/src/main/java/org/apache/velocity/tools/struts/ValidatorTool.java
velocity/tools/branches/2.0.x/xdocs/changes.xml
Modified: velocity/tools/branches/2.0.x/src/main/java/org/apache/velocity/tools/struts/ValidatorTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.0.x/src/main/java/org/apache/velocity/tools/struts/ValidatorTool.java?rev=1297754&r1=1297753&r2=1297754&view=diff
==============================================================================
--- velocity/tools/branches/2.0.x/src/main/java/org/apache/velocity/tools/struts/ValidatorTool.java (original)
+++ velocity/tools/branches/2.0.x/src/main/java/org/apache/velocity/tools/struts/ValidatorTool.java Tue Mar 6 22:08:57 2012
@@ -26,9 +26,11 @@ import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
+import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.validator.Field;
import org.apache.commons.validator.Form;
import org.apache.commons.validator.ValidatorAction;
@@ -432,8 +434,6 @@ public class ValidatorTool
return results.toString();
}
-
-
/**
* Generates the dynamic JavaScript for the form.
*
@@ -518,7 +518,14 @@ public class ValidatorTool
results.append(" = new Array(\"");
results.append(field.getKey()); // TODO: escape?
results.append("\", \"");
- results.append(escapeJavascript(message));
+
+ message = escapeJavascript(message);
+
+ // Escape required XML entities if we are in XHTML mode without CDATA
+ if(this.xhtml && !this.cdata)
+ message = StringEscapeUtils.escapeXml(message);
+
+ results.append(message);
results.append("\", new Function (\"varName\", \"");
Map<String,Var> vars = (Map<String,Var>)field.getVars();
@@ -543,6 +550,10 @@ public class ValidatorTool
String escapedVarValue = escapeJavascript(varValue);
+ // Escape required XML entities if we are in XHTML mode without CDATA
+ if(this.xhtml && !this.cdata)
+ escapedVarValue = StringEscapeUtils.escapeXml(escapedVarValue);
+
if (Var.JSTYPE_INT.equalsIgnoreCase(jsType))
{
results.append("=");
@@ -636,7 +647,12 @@ public class ValidatorTool
*/
protected String createMethods(List actions)
{
- String methodOperator = " && ";
+ String methodOperator;
+ // Escape required XML entities if we are in XHTML mode without CDATA
+ if(this.xhtml && !this.cdata)
+ methodOperator = " && ";
+ else
+ methodOperator = " && ";
StringBuilder methods = null;
for (Iterator i = actions.iterator(); i.hasNext();)
@@ -765,7 +781,6 @@ public class ValidatorTool
sb.append(" var formValidationResult;\n");
sb.append(" formValidationResult = " + methods + "; \n");
sb.append(" return (formValidationResult == 1);\n");
-
}
sb.append(" } \n\n");
Modified: velocity/tools/branches/2.0.x/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.0.x/xdocs/changes.xml?rev=1297754&r1=1297753&r2=1297754&view=diff
==============================================================================
--- velocity/tools/branches/2.0.x/xdocs/changes.xml (original)
+++ velocity/tools/branches/2.0.x/xdocs/changes.xml Tue Mar 6 22:08:57 2012
@@ -40,8 +40,9 @@
<li>fixed VELTOOLS-145 changed StrutsLinkTool's parent class to restore API backward-compatibility (schultz)</li>
<li>fixed VELTOOLS-148 - fixed a LinkTool bug with parametersToIgnore management (schultz)</li>
<li>fixed VELTOOLS-149 - changed LinkTool.addRequestParams to accept Object[] (schultz)</li>
- <li>Added StrutsLinkTool.action and StrutsLinkTool.forward methods as replacements for StrutsLinkTool.setAction ant StrutsLinkTool.setForward to match other new LinkTool methods like LinkTool.relative and LinkTool.absolute (schultz)
+ <li>Added StrutsLinkTool.action and StrutsLinkTool.forward methods as replacements for StrutsLinkTool.setAction and StrutsLinkTool.setForward to match other new LinkTool methods like LinkTool.relative and LinkTool.absolute (schultz)
<li>fixed VELTOOLS-146 $link.absolute($uri) should not encode query strings in the argument</li>
+ <li>fixed VELTOOLS-152 ValidatorTool generates invalid XHTML even when in XHTML mode (schultz)</li>
</ul>
</subsection>