tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1498693 - in /tomcat/trunk: java/org/apache/catalina/ssi/ExpressionTokenizer.java test/org/apache/catalina/ssi/TestExpressionParseTree.java
Date Mon, 01 Jul 2013 21:18:58 GMT
Author: markt
Date: Mon Jul  1 21:18:57 2013
New Revision: 1498693

URL: http://svn.apache.org/r1498693
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=55176
SSI expression parser failed to correctly handle the use of an '=' character inside a regular
expression.
Includes a test case.

Modified:
    tomcat/trunk/java/org/apache/catalina/ssi/ExpressionTokenizer.java
    tomcat/trunk/test/org/apache/catalina/ssi/TestExpressionParseTree.java

Modified: tomcat/trunk/java/org/apache/catalina/ssi/ExpressionTokenizer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ssi/ExpressionTokenizer.java?rev=1498693&r1=1498692&r2=1498693&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/ssi/ExpressionTokenizer.java (original)
+++ tomcat/trunk/java/org/apache/catalina/ssi/ExpressionTokenizer.java Mon Jul  1 21:18:57
2013
@@ -135,8 +135,8 @@ public class ExpressionTokenizer {
                 break;
         }
         int end = index;
-        // If it's a quoted string then end is the next unescaped quote
         if (currentChar == '"' || currentChar == '\'') {
+            // It's a quoted string and the end is the next unescaped quote
             char endChar = currentChar;
             boolean escaped = false;
             start++;
@@ -150,6 +150,19 @@ public class ExpressionTokenizer {
             }
             end = index;
             index++; // Skip the end quote
+        } else if (currentChar == '/') {
+            // It's a regular expression and the end is the next unescaped /
+            char endChar = currentChar;
+            boolean escaped = false;
+            for (; index < length; index++) {
+                if (expr[index] == '\\' && !escaped) {
+                    escaped = true;
+                    continue;
+                }
+                if (expr[index] == endChar && !escaped) break;
+                escaped = false;
+            }
+            end = ++index;
         } else {
             // End is the next whitespace character
             for (; index < length; index++) {

Modified: tomcat/trunk/test/org/apache/catalina/ssi/TestExpressionParseTree.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/ssi/TestExpressionParseTree.java?rev=1498693&r1=1498692&r2=1498693&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/ssi/TestExpressionParseTree.java (original)
+++ tomcat/trunk/test/org/apache/catalina/ssi/TestExpressionParseTree.java Mon Jul  1 21:18:57
2013
@@ -114,6 +114,28 @@ public class TestExpressionParseTree {
     }
 
 
+    @Test
+    public void testBug55176a() throws Exception {
+        SSIExternalResolver r = new TesterSSIExternalResolver();
+        r.setVariableValue("QUERY_STRING", "a=");
+        SSIMediator mediator = new SSIMediator(r, LAST_MODIFIED);
+        ExpressionParseTree ept =
+                new ExpressionParseTree("$QUERY_STRING = /a=/", mediator);
+        Assert.assertTrue(ept.evaluateTree());
+    }
+
+
+    @Test
+    public void testBug55176b() throws Exception {
+        SSIExternalResolver r = new TesterSSIExternalResolver();
+        r.setVariableValue("QUERY_STRING", "a");
+        SSIMediator mediator = new SSIMediator(r, LAST_MODIFIED);
+        ExpressionParseTree ept =
+                new ExpressionParseTree("$QUERY_STRING = /a=/", mediator);
+        Assert.assertFalse(ept.evaluateTree());
+    }
+
+
     /**
      * Minimal implementation that provides the bare essentials require for the
      * unit tests.



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


Mime
View raw message