You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2014/01/18 20:43:32 UTC

svn commit: r1559401 - in /tomcat/tc7.0.x/trunk: ./ java/org/apache/jasper/compiler/ELParser.java test/org/apache/jasper/compiler/TestELParser.java webapps/docs/changelog.xml

Author: markt
Date: Sat Jan 18 19:43:32 2014
New Revision: 1559401

URL: http://svn.apache.org/r1559401
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=56029 a regression in the fix for https://issues.apache.org/bugzilla/show_bug.cgi?id=55198
Remove the code to skip whitespace from the 'simple'EL parser. It is far simpler to retain the whitespace than it is to teach this simple parser parser when to insert it. This also has the benefit that the EL should remain unchanged.
Add a number of test cases for BZ 56029

Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/ELParser.java
    tomcat/tc7.0.x/trunk/test/org/apache/jasper/compiler/TestELParser.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
  Merged /tomcat/trunk:r1559397

Modified: tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/ELParser.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/ELParser.java?rev=1559401&r1=1559400&r2=1559401&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/ELParser.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/ELParser.java Sat Jan 18 19:43:32 2014
@@ -103,7 +103,7 @@ public class ELParser {
 
         StringBuilder buf = new StringBuilder();
         ELexpr = new ELNode.Nodes();
-        while (hasNext()) {
+        while (hasNextChar()) {
             curToken = nextToken();
             if (curToken instanceof Char) {
                 if (curToken.toChar() == '}') {
@@ -140,16 +140,16 @@ public class ELParser {
         }
         String s1 = null; // Function prefix
         String s2 = curToken.toString(); // Function name
-        if (hasNext()) {
+        if (hasNextChar()) {
             int mark = getIndex();
             curToken = nextToken();
             if (curToken.toChar() == ':') {
-                if (hasNext()) {
+                if (hasNextChar()) {
                     Token t2 = nextToken();
                     if (t2 instanceof Id) {
                         s1 = s2;
                         s2 = t2.toString();
-                        if (hasNext()) {
+                        if (hasNextChar()) {
                             curToken = nextToken();
                         }
                     }
@@ -169,11 +169,12 @@ public class ELParser {
      * Test if an id is a reserved word in EL
      */
     private boolean isELReserved(String id) {
+        String trimmed = id.trim();
         int i = 0;
         int j = reservedWords.length;
         while (i < j) {
             int k = (i + j) / 2;
-            int result = reservedWords[k].compareTo(id);
+            int result = reservedWords[k].compareTo(trimmed);
             if (result == 0) {
                 return true;
             }
@@ -232,20 +233,10 @@ public class ELParser {
     }
 
     /*
-     * @return true if there is something left in EL expression buffer other
-     * than white spaces.
-     */
-    private boolean hasNext() {
-        skipSpaces();
-        return hasNextChar();
-    }
-
-    /*
      * @return The next token in the EL expression buffer.
      */
     private Token nextToken() {
         prevToken = curToken;
-        skipSpaces();
         if (hasNextChar()) {
             char ch = nextChar();
             if (Character.isJavaIdentifierStart(ch)) {
@@ -299,14 +290,6 @@ public class ELParser {
      * expression buffer.
      */
 
-    private void skipSpaces() {
-        while (hasNextChar()) {
-            if (expression.charAt(index) > ' ')
-                break;
-            index++;
-        }
-    }
-
     private boolean hasNextChar() {
         return index < expression.length();
     }

Modified: tomcat/tc7.0.x/trunk/test/org/apache/jasper/compiler/TestELParser.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/jasper/compiler/TestELParser.java?rev=1559401&r1=1559400&r2=1559401&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/jasper/compiler/TestELParser.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/jasper/compiler/TestELParser.java Sat Jan 18 19:43:32 2014
@@ -85,6 +85,49 @@ public class TestELParser {
     }
 
 
+    @Test
+    public void testTernary01() throws JasperException {
+        doTestParser("${true?true:false}");
+    }
+
+
+    @Test
+    public void testTernary02() throws JasperException {
+        doTestParser("${a==1?true:false}");
+    }
+
+
+    @Test
+    public void testTernary03() throws JasperException {
+        doTestParser("${a eq1?true:false}");
+    }
+
+
+    @Test
+    public void testTernary04() throws JasperException {
+        doTestParser(" ${ a eq 1 ? true : false } ");
+    }
+
+
+    @Test
+    public void testTernary05() throws JasperException {
+        // Note this is invalid EL
+        doTestParser("${aeq1?true:false}");
+    }
+
+
+    @Test
+    public void testTernary06() throws JasperException {
+        doTestParser("${do:it(a eq1?true:false,y)}");
+    }
+
+
+    @Test
+    public void testTernary07() throws JasperException {
+        doTestParser(" $ { do:it( a eq 1 ? true : false, y ) } ");
+    }
+
+
     private void doTestParser(String input) throws JasperException {
         Nodes nodes = ELParser.parse(input, false);
 

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1559401&r1=1559400&r2=1559401&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Sat Jan 18 19:43:32 2014
@@ -142,6 +142,11 @@
         <code>JspWriter.DEFAULT_BUFFER</code>. Based on a patch by Eugene Chung.
         (markt)
       </fix>
+      <fix>
+        <bug>56029</bug>: A regression in the fix for <bug>55198</bug> meant
+        that when EL containing a ternary expression was used in an attribute
+        a compilation error would occur for some expressions. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Web applications">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org