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

chibenwa pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-jspf.git


The following commit(s) were added to refs/heads/master by this push:
     new adb5798  [FIX] MacroExpand: use constant patterns for macro 
transformers
adb5798 is described below

commit adb5798112581eeae0af41d3ee6ca69e90914cd0
Author: Benoit TELLIER <[email protected]>
AuthorDate: Wed Nov 18 23:08:54 2026 +0100

    [FIX] MacroExpand: use constant patterns for macro transformers
    
    The digit, reverse and delimiter patterns were compiled into a shared
    instance field on each call. MacroExpand is shared by all checks of an
    SPF instance, so concurrent checks could read each other's pattern.
    Use static final patterns with local matchers instead.
---
 .../main/java/org/apache/james/jspf/core/MacroExpand.java | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/resolver/src/main/java/org/apache/james/jspf/core/MacroExpand.java 
b/resolver/src/main/java/org/apache/james/jspf/core/MacroExpand.java
index 4d08e9a..2074ccd 100644
--- a/resolver/src/main/java/org/apache/james/jspf/core/MacroExpand.java
+++ b/resolver/src/main/java/org/apache/james/jspf/core/MacroExpand.java
@@ -52,7 +52,11 @@ public class MacroExpand {
 
     private Pattern macroLettersExpPattern;
 
-    private Pattern cellPattern;
+    private static final Pattern DIGITS_PATTERN = Pattern.compile("\\d+");
+
+    private static final Pattern REVERSE_PATTERN = Pattern.compile("r");
+
+    private static final Pattern DELIMITERS_PATTERN = 
Pattern.compile("[\\.\\-\\+\\,\\/\\_\\=]+");
 
     private DNSService dnsProbe;
 
@@ -440,8 +444,7 @@ public class MacroExpand {
         }
 
         // Find number of domains to use
-        cellPattern = Pattern.compile("\\d+");
-        cellMatcher = cellPattern.matcher(replaceValue);
+        cellMatcher = DIGITS_PATTERN.matcher(replaceValue);
         while (cellMatcher.find()) {
             domainNumber = cellMatcher.group();
             if (parseDigitTransformer(domainNumber) == 0) {
@@ -450,15 +453,13 @@ public class MacroExpand {
             }
         }
         // find if reversed
-        cellPattern = Pattern.compile("r");
-        cellMatcher = cellPattern.matcher(replaceValue);
+        cellMatcher = REVERSE_PATTERN.matcher(replaceValue);
         while (cellMatcher.find()) {
             isReversed = true;
         }
 
         // find delimeters
-        cellPattern = Pattern.compile("[\\.\\-\\+\\,\\/\\_\\=]+");
-        cellMatcher = cellPattern.matcher(replaceValue);
+        cellMatcher = DELIMITERS_PATTERN.matcher(replaceValue);
         while (cellMatcher.find()) {
             delimeters = cellMatcher.group();
         }


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

Reply via email to