You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by rd...@apache.org on 2009/04/08 18:22:55 UTC
svn commit: r763305 - in /james/jsieve/trunk/main/src:
main/java/org/apache/jsieve/comparators/ComparatorUtils.java
main/java/org/apache/jsieve/tests/Header.java
test/java/org/apache/jsieve/WierdAddressTest.java
Author: rdonkin
Date: Wed Apr 8 16:22:55 2009
New Revision: 763305
URL: http://svn.apache.org/viewvc?rev=763305&view=rev
Log:
Added workaround for issue with Pattern. SIEVE-49
Added:
james/jsieve/trunk/main/src/test/java/org/apache/jsieve/WierdAddressTest.java
Modified:
james/jsieve/trunk/main/src/main/java/org/apache/jsieve/comparators/ComparatorUtils.java
james/jsieve/trunk/main/src/main/java/org/apache/jsieve/tests/Header.java
Modified: james/jsieve/trunk/main/src/main/java/org/apache/jsieve/comparators/ComparatorUtils.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/main/src/main/java/org/apache/jsieve/comparators/ComparatorUtils.java?rev=763305&r1=763304&r2=763305&view=diff
==============================================================================
--- james/jsieve/trunk/main/src/main/java/org/apache/jsieve/comparators/ComparatorUtils.java (original)
+++ james/jsieve/trunk/main/src/main/java/org/apache/jsieve/comparators/ComparatorUtils.java Wed Apr 8 16:22:55 2009
@@ -19,6 +19,7 @@
package org.apache.jsieve.comparators;
+import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
@@ -84,7 +85,8 @@
// TODO Is there a way to re-use the compiled pattern?
try {
String regex = sieveToJavaRegex(glob);
- return Pattern.compile(regex).matcher(string).matches();
+ final Matcher matcher = Pattern.compile(regex).matcher(string);
+ return matcher.matches();
} catch (PatternSyntaxException e) {
throw new SievePatternException(e.getMessage());
}
@@ -142,10 +144,17 @@
public static String sieveToJavaRegex(String pattern) {
int ch;
StringBuffer buffer = new StringBuffer(2 * pattern.length());
+ boolean lastCharWasStar = false;
for (ch = 0; ch < pattern.length(); ch++) {
- switch (pattern.charAt(ch)) {
+ final char nextChar = pattern.charAt(ch);
+ switch (nextChar) {
case '*':
- buffer.append(".*");
+ //
+ // Java Matcher has issues with repeated stars
+ //
+ if (!lastCharWasStar) {
+ buffer.append(".*");
+ }
break;
case '?':
buffer.append('.');
@@ -160,11 +169,13 @@
buffer.append('\\');
break;
default:
- if (isRegexSpecialChar(pattern.charAt(ch)))
+ if (isRegexSpecialChar(nextChar))
buffer.append('\\');
- buffer.append(pattern.charAt(ch));
+ buffer.append(nextChar);
break;
}
+ // Workaround for issue with Java Matcher
+ lastCharWasStar = '*' == nextChar;
}
return buffer.toString();
}
Modified: james/jsieve/trunk/main/src/main/java/org/apache/jsieve/tests/Header.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/main/src/main/java/org/apache/jsieve/tests/Header.java?rev=763305&r1=763304&r2=763305&view=diff
==============================================================================
--- james/jsieve/trunk/main/src/main/java/org/apache/jsieve/tests/Header.java (original)
+++ james/jsieve/trunk/main/src/main/java/org/apache/jsieve/tests/Header.java Wed Apr 8 16:22:55 2009
@@ -224,8 +224,9 @@
boolean isMatched = false;
Iterator keysIter = keys.iterator();
while (!isMatched && keysIter.hasNext()) {
+ final String nextKey = (String) keysIter.next();
isMatched = ComparatorUtils.match(comparator, matchType,
- headerValue, (String) keysIter.next(), context);
+ headerValue, nextKey, context);
}
return isMatched;
}
Added: james/jsieve/trunk/main/src/test/java/org/apache/jsieve/WierdAddressTest.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/main/src/test/java/org/apache/jsieve/WierdAddressTest.java?rev=763305&view=auto
==============================================================================
--- james/jsieve/trunk/main/src/test/java/org/apache/jsieve/WierdAddressTest.java (added)
+++ james/jsieve/trunk/main/src/test/java/org/apache/jsieve/WierdAddressTest.java Wed Apr 8 16:22:55 2009
@@ -0,0 +1,41 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you 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. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.jsieve;
+
+import junit.framework.TestCase;
+
+import org.apache.jsieve.utils.JUnitUtils;
+import org.apache.jsieve.utils.SieveMailAdapter;
+
+public class WierdAddressTest extends TestCase {
+
+ /**
+ * My god - it's full of stars
+ */
+ public void testShouldParseAddressWithLotsOfStars() throws Exception {
+ String script = "if anyof (header :matches \"from\"" +
+ "\"**********************************************address@yahoo.com\" ," +
+ "header :is \"subject\" \"5\" )" +
+ "{ fileinto \"Whatever\"; stop;}";
+ SieveMailAdapter mail = (SieveMailAdapter) JUnitUtils.createMail();
+ mail.getMessage().addHeader("From", "user@domain");
+ JUnitUtils.interpret(mail, script);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org