You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2006/06/01 11:19:52 UTC

svn commit: r410807 - in /cocoon/branches/BRANCH_2_1_X: src/java/org/apache/cocoon/matching/helpers/WildcardHelper.java src/test/org/apache/cocoon/matching/helpers/WildcardHelperTestCase.java status.xml

Author: cziegeler
Date: Thu Jun  1 02:19:51 2006
New Revision: 410807

URL: http://svn.apache.org/viewvc?rev=410807&view=rev
Log:
Fix bug in wildcard matcher where a uri containing a pattern twice did not always match. For example,
the uri "hallo.xml.xml" did not match "*.xml".

Modified:
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/matching/helpers/WildcardHelper.java
    cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/matching/helpers/WildcardHelperTestCase.java
    cocoon/branches/BRANCH_2_1_X/status.xml

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/matching/helpers/WildcardHelper.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/matching/helpers/WildcardHelper.java?rev=410807&r1=410806&r2=410807&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/matching/helpers/WildcardHelper.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/matching/helpers/WildcardHelper.java Thu Jun  1 02:19:51 2006
@@ -153,7 +153,6 @@
         // The position in the expression, input, translation and result arrays
         int exprpos = 0;
         int buffpos = 0;
-        int rsltpos = 0;
         int offset = -1;
 
         // The matching count
@@ -206,12 +205,26 @@
 
             // Check for END's
             if (exprchr == MATCH_END) {
-                if (rsltpos > 0 && map != null ) {
-                    map.put (Integer.toString(++mcount),new String(rslt, 0, rsltpos));
+                // Check that we reached buffer's end
+                // if not, we'll search again!
+                if ( buffpos != buff.length ) {
+                    int startpos = buffpos - (charpos - exprpos);
+                    while ( buffpos != buff.length ) {
+                        buffpos -= (charpos - exprpos);
+                        buffpos++;
+                        offset = indexOfArray (expr, exprpos, charpos, buff, buffpos);
+                        if (offset < 0) {
+                            return false;
+                        }
+                        buffpos = offset + (charpos - exprpos);    
+                    }
+                    // replace value in result map
+                    if (map != null ) {
+                        String oldValue = (String)map.get(Integer.toString(mcount));
+                        map.put (Integer.toString(mcount), oldValue + new String(buff, startpos, offset - startpos));
+                    }
                 }
-                // Check that we reach buffer's end
-                // FIXME - if (buffpos != buff.length) then we have to search the expr again!
-                return (buffpos == buff.length);
+                return true;
             }
 
             // Search the next expression character
@@ -227,19 +240,23 @@
                     lastIndexOfArray (expr, exprpos, charpos, buff,
                     buffpos);
 
-            if (offset < 0)
-                return (false);
+            if (offset < 0) {
+                return false;
+            }
 
             // Copy the data from the source buffer into the result buffer
             // to substitute the expression character
+            int rsltpos = 0;
             if (prevchr == MATCH_PATH) {
-                while (buffpos < offset)
+                while (buffpos < offset) {
                     rslt[rsltpos++] = buff[buffpos++];
+                }
             } else {
                 // Matching file, don't copy '/'
                 while (buffpos < offset) {
-                    if (buff[buffpos] == '/')
-                        return (false);
+                    if (buff[buffpos] == '/') {
+                        return false;
+                    }
                     rslt[rsltpos++] = buff[buffpos++];
                 }
             }
@@ -247,7 +264,6 @@
             if ( map != null ) {
                 map.put(Integer.toString(++mcount),new String (rslt, 0, rsltpos));
             }
-            rsltpos = 0;
         }
     }
 

Modified: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/matching/helpers/WildcardHelperTestCase.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/matching/helpers/WildcardHelperTestCase.java?rev=410807&r1=410806&r2=410807&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/matching/helpers/WildcardHelperTestCase.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/matching/helpers/WildcardHelperTestCase.java Thu Jun  1 02:19:51 2006
@@ -59,13 +59,23 @@
 
     public void testWildcardURIMatchDoublePattern() throws Exception {
         final Map resultMap = new HashMap();
-        final String uri = "test/something.xmlbla.xml";
+        final String uri = "test/something.xml";
         final String pattern = "*/*.xml";
         int[] expr = WildcardHelper.compilePattern(pattern);
         boolean result = WildcardHelper.match(resultMap, uri, expr);
         assertTrue("Test if url matches: " + uri + " - " + pattern, result);
         assertEquals("Test if result matches for {0}", uri, resultMap.get("0"));
         assertEquals("Test if result matches for {1}", "test", resultMap.get("1"));
-        assertEquals("Test if result matches for {2}", "something.xmlbla", resultMap.get("2"));
+        assertEquals("Test if result matches for {2}", "something", resultMap.get("2"));
+
+        final Map resultMap2 = new HashMap();
+        final String uri2 = "test/something.xmlbla.xml";
+        final String pattern2 = "*/*.xml";
+        int[] expr2 = WildcardHelper.compilePattern(pattern2);
+        boolean result2 = WildcardHelper.match(resultMap2, uri2, expr2);
+        assertTrue("Test if url matches: " + uri2 + " - " + pattern2, result2);
+        assertEquals("Test if result matches for {0}", uri2, resultMap2.get("0"));
+        assertEquals("Test if result matches for {1}", "test", resultMap2.get("1"));
+        assertEquals("Test if result matches for {2}", "something.xmlbla", resultMap2.get("2"));
     }
 }

Modified: cocoon/branches/BRANCH_2_1_X/status.xml
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/status.xml?rev=410807&r1=410806&r2=410807&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml Thu Jun  1 02:19:51 2006
@@ -182,6 +182,10 @@
   <release version="@version@" date="@date@">
 -->
   <release version="2.1.10" date="TBD">
+    <action dev="CZ" type="fix">
+      Fix bug in wildcard matcher where a uri containing a pattern twice did not always match. For example,
+      the uri "hallo.xml.xml" did not match "*.xml".
+    </action>
     <action dev="AG" type="fix" fixes-bug="COCOON-1848" due-to="Vincent Demay" due-to-email="vincent.demay@anyware-tech.com">
       CForms: Using setRequired in Ajax mode does not generate bu:replace.
     </action>