TracSpamFilter - traceback

25 views
Skip to first unread message

JP 99

unread,
Jun 13, 2024, 4:20:36 PM6/13/24
to Trac Users
Hi, ubuntu 22.04/trac-1.6/tracspamfilter-1.5.3/accountmanager-0.6.0

Account Policy set to RegistrationFilterAdapter.

Registering a user "test" I get in trac.log:

Trac[filtersystem] ERROR: Filter strategy <Component tracspamfilter.filters.registration.RegistrationFilterStrategy> raised exception: 'Fragment' object has no attribute 'replace'
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/tracspamfilter/filters/registration.py", line 81, in test
    check.validate_registration(req)
  File "/usr/local/lib/python3.10/dist-packages/acct_mgr/register.py", line 289, in validate_registration
    raise RegistrationError(tag_(
acct_mgr.register.RegistrationError: Username <b>test</b> doesn't match local naming policy.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/tracspamfilter/filtersystem.py", line 200, in test
    retval = strategy.test(req, author, content, ip)
  File "/usr/local/lib/python3.10/dist-packages/tracspamfilter/filters/registration.py", line 84, in test
    msg = e.message.replace('\n', '')
AttributeError: 'Fragment' object has no attribute 'replace'

Jun Omae

unread,
Jun 13, 2024, 10:41:13 PM6/13/24
to trac-...@googlegroups.com
Hi,
It seems to be an issue of the spam-filter plugin. Please try the following patch:

Index: tracspamfilter/filters/registration.py
===================================================================
--- tracspamfilter/filters/registration.py (revision 17823)
+++ tracspamfilter/filters/registration.py (working copy)
@@ -16,7 +16,8 @@

from trac.config import BoolOption, IntOption
from trac.core import Component, ExtensionPoint, implements
-from trac.util.html import tag
+from trac.util.html import striptags, tag
+from trac.util.text import to_unicode

from tracspamfilter.api import IFilterStrategy, N_

@@ -81,11 +82,7 @@
check.validate_registration(req)
except RegistrationError as e:
karma -= abs(self.karma_points)
- msg = e.message.replace('\n', '')
- args = e.msg_args
- if args:
- msg = msg % args
- msg.replace('<b>', '*').replace('</b>', '*')
+ msg = striptags(to_unicode(e))
self.log.debug("Registration check returned %s", msg)
checks.append('%s: %s' % (check.__class__.__name__, msg))
except Exception as e:


--
Jun Omae <jun...@gmail.com> (大前 潤)

JP 99

unread,
Jun 14, 2024, 3:10:49 AM6/14/24
to Trac Users
Thank you so much - that looks to have worked perfectly.
Reply all
Reply to author
Forward
0 new messages