jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1341862 - in /jackrabbit/oak/trunk/oak-mk/src: main/java/org/apache/jackrabbit/mk/util/NameFilter.java test/java/org/apache/jackrabbit/mk/util/NameFilterTest.java
Date Wed, 23 May 2012 13:44:48 GMT
Author: stefan
Date: Wed May 23 13:44:48 2012
New Revision: 1341862

URL: http://svn.apache.org/viewvc?rev=1341862&view=rev
Log:
OAK-75: specify format and semantics of 'filter' parameter in MicroKernel API (WIP)

Modified:
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/util/NameFilter.java
    jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/util/NameFilterTest.java

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/util/NameFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/util/NameFilter.java?rev=1341862&r1=1341861&r2=1341862&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/util/NameFilter.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/util/NameFilter.java
Wed May 23 13:44:48 2012
@@ -25,14 +25,23 @@ import java.util.List;
  * <li>a filter consists of one or more <i>globs</i></li>
  * <li>a <i>glob</i> prefixed by {@code -} (dash) is treated as an exclusion
pattern;
  * all others are considered inclusion patterns</li>
- * <li>{@code *} (asterisk) serves as a <i>wildcard</i>, i.e. it matches
any substring in the target name</li>
+ * <li>a leading {@code -} (dash) must be escaped by prepending {@code \} (backslash)
+ * if it should be interpreted as a literal</li>
+ * <li>{@code *} (asterisk) serves as a <i>wildcard</i>, i.e. it matches
any
+ * substring in the target name</li>
+ * <li>{@code *} (asterisk) occurrences within the glob to be interpreted as
+ * literals must be escaped by prepending {@code \} (backslash)</li>
  * <li>a filter matches a target name if any of the inclusion patterns match but
  * none of the exclusion patterns</li>
  * </ul>
- * Example:
+ * Examples:
  * <p/>
  * {@code ["foo*", "-foo99"]} matches {@code "foo"} and {@code "foo bar"}
  * but not {@code "foo99"}.
+ * <p/>
+ * {@code ["foo\*"]} matches {@code "foo*"} but not {@code "foo99"}.
+ * <p/>
+ * {@code ["\-blah"]} matches {@code "-blah"}.
  */
 public class NameFilter {
 
@@ -121,11 +130,16 @@ public class NameFilter {
             }
 
             if (pOff < pLen && sOff < sLen) {
-                // check for ESCAPE character
+                // check for escape sequences
                 if (pattern.charAt(pOff) == ESCAPE) {
+                    // * to be interpreted as literal
                     if (pOff < pLen - 1
-                            && (pattern.charAt(pOff + 1) == WILDCARD
-                                || pattern.charAt(pOff + 1) == EXCLUDE_PREFIX)) {
+                            && pattern.charAt(pOff + 1) == WILDCARD) {
+                        ++pOff;
+                    }
+                    // leading - to be interpreted as literal
+                    if (pOff == 0 && pLen > 1
+                            && pattern.charAt(pOff + 1) == EXCLUDE_PREFIX) {
                         ++pOff;
                     }
                 }

Modified: jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/util/NameFilterTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/util/NameFilterTest.java?rev=1341862&r1=1341861&r2=1341862&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/util/NameFilterTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/util/NameFilterTest.java
Wed May 23 13:44:48 2012
@@ -37,11 +37,44 @@ public class NameFilterTest {
 
         filter = new NameFilter(new String[]{"*foo"});
         assertTrue(filter.matches("foo"));
+        assertTrue(filter.matches("-123foo"));
         assertFalse(filter.matches("bar"));
 
         filter = new NameFilter(new String[]{"foo\\*bar"});
         assertFalse(filter.matches("foo bar"));
         assertTrue(filter.matches("foo*bar"));
-    }
 
+        filter = new NameFilter(new String[]{"foo\\bar"});
+        assertTrue(filter.matches("foo\\bar"));
+
+        filter = new NameFilter(new String[]{"foo\\"});
+        assertTrue(filter.matches("foo\\"));
+
+        filter = new NameFilter(new String[]{"*"});
+        assertTrue(filter.matches("*"));
+        assertTrue(filter.matches("\\*"));
+        assertTrue(filter.matches("blah"));
+
+        filter = new NameFilter(new String[]{"\\*"});
+        assertTrue(filter.matches("*"));
+        assertFalse(filter.matches("\\*"));
+        assertFalse(filter.matches("blah"));
+
+        filter = new NameFilter(new String[]{"\\- topic"});
+        assertTrue(filter.matches("- topic"));
+
+        filter = new NameFilter(new String[]{"*", "- topic"});
+        assertFalse(filter.matches(" topic"));
+        assertTrue(filter.matches("- topic"));
+        assertTrue(filter.matches("blah"));
+
+        filter = new NameFilter(new String[]{"foo\\-bar"});
+        assertFalse(filter.matches("foo-bar"));
+        assertTrue(filter.matches("foo\\-bar"));
+
+        filter = new NameFilter(new String[]{"foo\\\\*bar"});
+        assertTrue(filter.matches("foo\\*bar"));
+        assertFalse(filter.matches("foo\\ blah bar"));
+        assertFalse(filter.matches("foo*bar"));
+    }
 }



Mime
View raw message