Author: gbechis
Date: Wed Mar 4 17:23:04 2026
New Revision: 1932162
Log:
If the named capture regexp doesn't match, substitute the part of the regexp with a token that will never match and continue processing the regexp
bz #8360
Modified:
spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm
spamassassin/trunk/t/regexp_named_capture.t
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm Wed Mar 4 16:57:42 2026 (r1932161)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm Wed Mar 4 17:23:04 2026 (r1932162)
@@ -1392,18 +1392,20 @@ sub capture_rules_replace {
q{'.$rulename.'}, $cname, $test_qr);
';
}
+ # bz 8360, instead of disabling the entire rule, change the part of the regexp that doesn't match to
+ # a different regexp that will never match (without capture tags)
$code .= '
} else {
+ my $cval = "(?!)";
+ $test_qr =~ s/(?<!\\\\)\\%\\\\\\{\Q${cname}\E\\\\\\}/$cval/gs;
';
if ($would_log_rules_all) {
$code .= '
- dbg("rules-all: not running rule %s, dependent tag not defined: %s",
+ dbg("rules-all: dependent tag not defined on rule %s, using empty alternation: %s",
q{'.$rulename.'}, $cname);
';
}
$code .= '
- $test_qr = undef;
- last;
}
}
if ($test_qr) {
Modified: spamassassin/trunk/t/regexp_named_capture.t
==============================================================================
--- spamassassin/trunk/t/regexp_named_capture.t Wed Mar 4 16:57:42 2026 (r1932161)
+++ spamassassin/trunk/t/regexp_named_capture.t Wed Mar 4 17:23:04 2026 (r1932162)
@@ -5,7 +5,7 @@ use lib 't';
use SATest; sa_t_init("regexp_named_capture");
use Test::More;
-plan tests => 14;
+plan tests => 16;
# ---------------------------------------------------------------------------
@@ -46,5 +46,28 @@ tstlocalrules (q{
});
sarun ("-D check,config -L -t < data/nice/001 2>&1", \&patterns_run_cb);
+ok_all_patterns();
+
+clear_pattern_counters();
+
+%patterns = (
+ q{ 1.0 TEST_CAPTURE_UNDEF_ALT } => '',
+);
+%anti_patterns = (
+ q{ 1.0 TEST_CAPTURE_UNDEF_ONLY } => '',
+);
+
+tstlocalrules (q{
+ # Capture from non-existent header, tag will be undefined
+ header __CAP_NOEXIST X-Nonexistent-Header =~ /@(?<TESTCAP_UNDEF>\w+)/
+
+ # Alternation with undefined tag: should still match "Evolution"
+ body TEST_CAPTURE_UNDEF_ALT /(?:%{TESTCAP_UNDEF}|Evolution)/
+
+ # Only undefined tag, no alternation: should not match
+ body TEST_CAPTURE_UNDEF_ONLY /%{TESTCAP_UNDEF}/
+});
+
+sarun ("-D check,config -L -t < data/nice/001 2>&1", \&patterns_run_cb);
ok_all_patterns();
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.