Repository navigation
fix: use a raw string for EMAIL_CATCH_ALL_PATTERN - #292
Merged
bokysan merged 1 commit intoJul 29, 2026
Merged
Conversation
On Python 3.12+ the pattern emits a SyntaxWarning at import time:
SyntaxWarning: "\[" is an invalid escape sequence.
Such sequences will not work in the future.
`\[`, `\.` and `\{` are not valid Python escapes, so they only survive by
accident. Python 3.12 turned the old DeprecationWarning into a visible
SyntaxWarning, so since v5.0.0 moved the image to Debian Trixie
(Python 3.13) it shows up at runtime.
It is not only noise. With ANONYMIZE_EMAILS set, rsyslog runs this script
through mmexternal and reads its replies over a pipe, so the warning ends
up on that channel and rsyslog logs it as a bad reply:
rsyslogd: mmexternal: invalid reply '.../email-anonymizer.py:37:
SyntaxWarning: invalid escape sequence '\[' ...' from program
'/scripts/email-anonymizer.sh'
That happens once per anonymizer process start (and again each time the
wrapper's retry loop restarts it), and the message being processed at
that moment is not anonymized.
Note that simply prefixing the existing literal with `r` would change the
pattern: the parts already written as `\\[` would become a literal
backslash followed by `[` inside the character class. The pre-escaped
sequences are therefore collapsed (`\\[` -> `\[`, `\\]` -> `\]`,
`\\{` -> `\{`) at the same time, which keeps the resulting pattern
byte-for-byte identical to before.
Verified: the compiled pattern string is unchanged, the warning is gone,
and the vectors from unit-tests/024 and 025 produce identical output
before and after across the noop, hash, paranoid and smart filters
(190 input x filter comparisons, no differences).
Owner
|
Nice catch! Thank you for the fix! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
image_root/scripts/email-anonymizer.py:37builds the catch-all pattern from a normal stringliteral containing
\[,\.and\{. None of those are valid Python escape sequences — theysurvive only because Python leaves unknown escapes as-is.
Python 3.12 promoted that from a
DeprecationWarningto a visibleSyntaxWarning, and sincev5.0.0 moved the image to Debian Trixie (Python 3.13) it now shows up at runtime:
It is more than cosmetic noise. With
ANONYMIZE_EMAILSset, rsyslog runs this script viammexternaland reads its replies over a pipe, so the warning lands on that channel and rsyslogrejects it as a bad reply:
This happens once per anonymizer process start — and again whenever the wrapper's
while ! ... ; do sleep 1; doneretry loop restarts it. The log message being processed at thatmoment doesn't get anonymized.
Fix
Make the literal a raw string.
One thing worth flagging for review: just adding the
rprefix would silently change thepattern. The literal already contains
\\[and\\]in the first character class, which in araw string would mean a literal backslash followed by
[— altering what the class matches. Sothe pre-escaped sequences are collapsed in the same change (
\\[→\[,\\]→\],\\{→\{), which leaves the compiled pattern byte-for-byte identical to before.Verification
repr()of the literal before and after).SyntaxWarningis gone; no other warnings appear.unit-tests/024_email-anonymizer-smart.batsandunit-tests/025_email-anonymizer-regexs.batsproduce identical output before and after,across the
noop,hash,paranoidandsmartfilters — 190 input × filter comparisons,zero differences.
025's own expectations still pass unchanged.