Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=48956
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 15 Jun 2011 22:44:00 +0000 (22:44 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 15 Jun 2011 22:44:00 +0000 (22:44 +0000)
Implement regular expression support for SSI

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

java/org/apache/catalina/ssi/ExpressionParseTree.java
webapps/docs/changelog.xml

index 854c6e0..a5b5544 100644 (file)
@@ -20,6 +20,7 @@ package org.apache.catalina.ssi;
 import java.text.ParseException;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.regex.Pattern;
 /**
  * Represents a parsed expression.
  * 
@@ -350,6 +351,21 @@ public class ExpressionParseTree {
         protected int compareBranches() {
             String val1 = ((StringNode)left).getValue();
             String val2 = ((StringNode)right).getValue();
+            
+            int val2Len = val2.length();
+            if (val2Len > 1 && val2.charAt(0) == '/' &&
+                    val2.charAt(val2Len - 1) == '/') {
+                // Treat as a regular expression
+                String expr = val2.substring(1, val2Len - 1);
+                Pattern pattern = Pattern.compile(expr);
+                // Regular expressions will only ever be used with EqualNode
+                // so return zero for equal and non-zero for not equal
+                if (pattern.matcher(val1).find()) {
+                    return 0;
+                } else {
+                    return -1;
+                }
+            }
             return val1.compareTo(val2);
         }
     }
index c33e8b4..8f3350f 100644 (file)
@@ -46,6 +46,9 @@
   <subsection name="Catalina">
     <changelog>
       <add>
+        <bug>48956</bug>: Add regular expression support for SSI. (markt)
+      </add>
+      <add>
         <bug>50677</bug>: Allow system property variables to be used in the
         values of "common.loader" and other "*.loader" properties in the
         <code>catalina.properties</code> file. (kkolinko)