This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch 3.6.x
in repository https://gitbox.apache.org/repos/asf/james-project.git


The following commit(s) were added to refs/heads/3.6.x by this push:
     new 90ec73f  JAMES-3635 Upgrade PrefixedRegex to RE2J
90ec73f is described below

commit 90ec73f3138e272896d110575eeb063f6eef1d9c
Author: Benoit Tellier <[email protected]>
AuthorDate: Sun Aug 22 20:40:53 2021 +0700

    JAMES-3635 Upgrade PrefixedRegex to RE2J
    
    https://github.com/google/re2j
---
 mailbox/api/pom.xml                                |  5 +++++
 .../james/mailbox/model/search/PrefixedRegex.java  |  3 ++-
 .../mailbox/model/search/PrefixedRegexTest.java    | 22 ++++++++++++++++++++++
 3 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/mailbox/api/pom.xml b/mailbox/api/pom.xml
index 8b34b84..7383fa6 100644
--- a/mailbox/api/pom.xml
+++ b/mailbox/api/pom.xml
@@ -72,6 +72,11 @@
             <artifactId>guava</artifactId>
         </dependency>
         <dependency>
+            <groupId>com.google.re2j</groupId>
+            <artifactId>re2j</artifactId>
+            <version>1.6</version>
+        </dependency>
+        <dependency>
             <groupId>com.ibm.icu</groupId>
             <artifactId>icu4j</artifactId>
         </dependency>
diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/search/PrefixedRegex.java
 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/search/PrefixedRegex.java
index 3f2be46..1040391 100644
--- 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/search/PrefixedRegex.java
+++ 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/search/PrefixedRegex.java
@@ -22,7 +22,8 @@ package org.apache.james.mailbox.model.search;
 import java.util.Objects;
 import java.util.Optional;
 import java.util.StringTokenizer;
-import java.util.regex.Pattern;
+
+import com.google.re2j.Pattern;
 
 public class PrefixedRegex implements MailboxNameExpression {
 
diff --git 
a/mailbox/api/src/test/java/org/apache/james/mailbox/model/search/PrefixedRegexTest.java
 
b/mailbox/api/src/test/java/org/apache/james/mailbox/model/search/PrefixedRegexTest.java
index 517eb72..95a2681 100644
--- 
a/mailbox/api/src/test/java/org/apache/james/mailbox/model/search/PrefixedRegexTest.java
+++ 
b/mailbox/api/src/test/java/org/apache/james/mailbox/model/search/PrefixedRegexTest.java
@@ -21,8 +21,14 @@ package org.apache.james.mailbox.model.search;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
 import org.junit.jupiter.api.Test;
 
+import com.google.re2j.Pattern;
+
 import nl.jqno.equalsverifier.EqualsVerifier;
 
 class PrefixedRegexTest {
@@ -34,10 +40,26 @@ class PrefixedRegexTest {
     public void shouldMatchBeanContract() {
         EqualsVerifier.forClass(PrefixedRegex.class)
             .withIgnoredFields("pattern")
+            .withPrefabValues(Pattern.class, Pattern.compile("a"), 
Pattern.compile("b"))
             .verify();
     }
 
     @Test
+    void slowRegexShouldNotBeConstructedByFuzzing() throws Exception {
+        ExecutorService executorService = Executors.newSingleThreadExecutor();
+
+        try {
+            executorService.submit(() -> {
+                PrefixedRegex prefixedRegex = new PrefixedRegex("", 
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%a", PATH_DELIMITER);
+
+                prefixedRegex.isExpressionMatch("aa%%%%%%%%%%%%%%%%");
+            }).get(30, TimeUnit.SECONDS);
+        } finally {
+            executorService.shutdownNow();
+        }
+    }
+
+    @Test
     void isWildShouldReturnTrueWhenOnlyFreeWildcard() {
         PrefixedRegex prefixedRegex = new PrefixedRegex(PREFIX, "*", 
PATH_DELIMITER);
 

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to