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/02 11:47:11 UTC
svn commit: r411110 - in /cocoon/branches/BRANCH_2_1_X/src:
java/org/apache/cocoon/matching/helpers/WildcardHelper.java
test/org/apache/cocoon/matching/helpers/WildcardHelperTestCase.java
Author: cziegeler
Date: Fri Jun 2 02:47:10 2006
New Revision: 411110
URL: http://svn.apache.org/viewvc?rev=411110&view=rev
Log:
Fix recently introduced bug
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
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=411110&r1=411109&r2=411110&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 Fri Jun 2 02:47:10 2006
@@ -1,12 +1,12 @@
/*
* Copyright 1999-2005 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -39,7 +39,6 @@
/** The int representing end in pattern <code>int []</code>. */
protected static final int MATCH_END = -5;
-
/**
* Translate the given <code>String</code> into a <code>int []</code>
* representing the pattern matchable by this class.
@@ -210,6 +209,9 @@
if ( buffpos != buff.length ) {
int startpos = buffpos - (charpos - exprpos);
while ( buffpos != buff.length ) {
+ if ( exprpos == charpos ) {
+ return false;
+ }
buffpos -= (charpos - exprpos);
buffpos++;
offset = indexOfArray (expr, exprpos, charpos, buff, buffpos);
@@ -289,7 +291,7 @@
throw new IllegalArgumentException ("rend < rpos");
// If we need to match a zero length string return current dpos
if (rend == rpos)
- return (d.length); //?? dpos?
+ return d.length; //?? dpos?
// If we need to match a 1 char length string do it simply
if ((rend - rpos) == 1) {
// Search for the specified character
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=411110&r1=411109&r2=411110&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 Fri Jun 2 02:47:10 2006
@@ -46,7 +46,7 @@
assertEquals("Test if result matches for {2}", "end", resultMap.get("2"));
}
- public void testWildcardURIMatchSimplePattern() throws Exception {
+ public void testSimplePattern() throws Exception {
final Map resultMap = new HashMap();
final String uri = "test";
final String pattern = "*";
@@ -57,7 +57,7 @@
assertEquals("Test if result matches for {1}", uri, resultMap.get("1"));
}
- public void testWildcardURIMatchDoublePattern() throws Exception {
+ public void testDoublePattern() throws Exception {
final Map resultMap = new HashMap();
final String uri = "test/something.xml";
final String pattern = "*/*.xml";
@@ -78,4 +78,19 @@
assertEquals("Test if result matches for {1}", "test", resultMap2.get("1"));
assertEquals("Test if result matches for {2}", "something.xmlbla", resultMap2.get("2"));
}
+
+ public void testEmptyPattern() throws Exception {
+ final Map resultMap = new HashMap();
+ final String pattern = "";
+ final int[] expr = WildcardHelper.compilePattern(pattern);
+ boolean result = WildcardHelper.match(resultMap, "something", expr);
+ assertFalse("Url 'something' should not match empty pattern.", result);
+
+ result = WildcardHelper.match(resultMap, "something/hello.gif", expr);
+ assertFalse("Url 'something/hello.gif' should not match empty pattern.", result);
+
+ result = WildcardHelper.match(resultMap, "", expr);
+ assertTrue("Empty url should match empty pattern", result);
+ }
+
}