Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=47331
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 2 Nov 2009 00:30:55 +0000 (00:30 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 2 Nov 2009 00:30:55 +0000 (00:30 +0000)
Uninterpreted tags are essentially template text so apply the rules of JSp.2.2 there too.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@831785 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/jasper/compiler/Validator.java
java/org/apache/jasper/resources/LocalStrings.properties

index fdc5a56..1d5ddfb 100644 (file)
@@ -731,9 +731,16 @@ class Validator {
                 int attrSize = attrs.getLength();
                 Node.JspAttribute[] jspAttrs = new Node.JspAttribute[attrSize];
                 for (int i = 0; i < attrSize; i++) {
+                    // JSP.2.2 - '#{' not allowed in template text
+                    String value = attrs.getValue(i);
+                    if (!pageInfo.isDeferredSyntaxAllowedAsLiteral()) {
+                        if (containsDeferredSyntax(value)) {
+                            err.jspError(n, "jsp.error.el.template.deferred");
+                        }
+                    }
                     jspAttrs[i] = getJspAttribute(null, attrs.getQName(i),
-                            attrs.getURI(i), attrs.getLocalName(i), attrs
-                                    .getValue(i), n, false);
+                            attrs.getURI(i), attrs.getLocalName(i), value, n,
+                            false);
                 }
                 n.setJspAttributes(jspAttrs);
             }
@@ -741,6 +748,31 @@ class Validator {
             visitBody(n);
         }
 
+        /*
+         * Look for a #{ sequence that isn't preceded by \.
+         */
+        private boolean containsDeferredSyntax(String value) {
+            if (value == null) {
+                return false;
+            }
+            
+            int i = 0;
+            int len = value.length();
+            boolean prevCharIsEscape = false;
+            while (i < value.length()) {
+                char c = value.charAt(i);
+                if (c == '#' && (i+1) < len && value.charAt(i+1) == '{' && !prevCharIsEscape) {
+                    return true;
+                } else if (c == '\\') {
+                    prevCharIsEscape = true;
+                } else {
+                    prevCharIsEscape = false;
+                }
+                i++;
+            }
+            return false;
+        }
+
         public void visit(Node.CustomTag n) throws JasperException {
 
             TagInfo tagInfo = n.getTagInfo();
@@ -1063,7 +1095,7 @@ class Validator {
                                 
                                 String expectedType = null;
                                 if (tldAttrs[j].isDeferredMethod()) {
-                                    // The String litteral must be castable to what is declared as type
+                                    // The String literal must be castable to what is declared as type
                                     // for the attribute
                                     String m = tldAttrs[j].getMethodSignature();
                                     if (m != null) {
index 29b5cba..0d3f635 100644 (file)
@@ -443,7 +443,7 @@ jsp.error.prefix.use_before_dcl=The prefix {0} specified in this tag directive h
 jsp.exception=An exception occurred processing JSP page {0} at line {1}
 
 # JSP 2.1
-jsp.error.el.template.deferred=#{..} is not allowed in template text
+jsp.error.el.template.deferred=#{...} is not allowed in template text
 jsp.error.el.parse={0} : {1}
 jsp.error.page.invalid.deferredsyntaxallowedasliteral=Page directive: invalid value for deferredSyntaxAllowedAsLiteral
 jsp.error.tag.invalid.deferredsyntaxallowedasliteral=Tag directive: invalid value for deferredSyntaxAllowedAsLiteral