fixed various pattern matching problems, including:
authormaxcooper <maxcooper>
Mon, 9 Dec 2002 12:23:03 +0000 (12:23 +0000)
committermaxcooper <maxcooper>
Mon, 9 Dec 2002 12:23:03 +0000 (12:23 +0000)
/foo/* not matching /foo
/bar/* matching /foo/bar/index.html
*.ext matching *.extention
/exact matching /exact/morestuff.html

src/share/org/securityfilter/filter/MatchableURLPattern.java

index 4e48537..28b86cf 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * $Header: /cvsroot/securityfilter/securityfilter/src/share/org/securityfilter/filter/Attic/MatchableURLPattern.java,v 1.5 2002/09/14 08:45:28 maxcooper Exp $
- * $Revision: 1.5 $
- * $Date: 2002/09/14 08:45:28 $
+ * $Header: /cvsroot/securityfilter/securityfilter/src/share/org/securityfilter/filter/Attic/MatchableURLPattern.java,v 1.6 2002/12/09 12:23:03 maxcooper Exp $
+ * $Revision: 1.6 $
+ * $Date: 2002/12/09 12:23:03 $
  *
  * ====================================================================
  * The SecurityFilter Software License, Version 1.1
@@ -69,7 +69,7 @@ import java.util.Collection;
  * by the order field).
  *
  * @author Max Cooper (max@maxcooper.com)
- * @version $Revision: 1.5 $ $Date: 2002/09/14 08:45:28 $
+ * @version $Revision: 1.6 $ $Date: 2002/12/09 12:23:03 $
  */
 public class MatchableURLPattern implements Comparable {
    private String pattern;
@@ -303,6 +303,23 @@ public class MatchableURLPattern implements Comparable {
          buf.replace(pos, pos + 1, ".*");
          pos = buf.toString().indexOf('*', pos + 2);
       }
+      // adjustments for the different expression types
+      switch (patternType) {
+         case PATH:
+            // make sure it matches from the start of the string
+            buf.insert(0, '^');
+            // make sure /foo/* matches /foo and /foo/morestuff, but not /foobar
+            buf.insert(buf.length()-3, "($|");
+            buf.append(")");
+            break;
+         case EXTENSION:
+            buf.append('$');
+            break;
+         case EXACT:
+            buf.insert(0, '^');
+            buf.append('$');
+            break;
+      }
       return buf.toString();
    }
 }