Modify ↓
Opened 18 months ago
Closed 18 months ago
#13759 closed defect (fixed)
RegistrationFilterStrategy raises AttributeError: 'Fragment' object has no attribute 'replace'
| Reported by: | Jun Omae | Owned by: | Dirk Stöcker |
|---|---|---|---|
| Priority: | normal | Milestone: | plugin - spam-filter |
| Component: | plugin/spamfilter | Version: | 1.6 |
| Severity: | normal | Keywords: | |
| Cc: | Branch: | ||
| Release Notes: | |||
| API Changes: | |||
| Internal Changes: | |||
Description
Originally reported at gmessage:trac-users:OKhqlyY5s0w/m/GJl9B2nlAAAJ.
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'
I think we could use to_unicode and striptags to extract the message from the RegistrationError exception.
-
tracspamfilter/filters/registration.py
16 16 17 17 from trac.config import BoolOption, IntOption 18 18 from trac.core import Component, ExtensionPoint, implements 19 from trac.util.html import tag 19 from trac.util.html import striptags, tag 20 from trac.util.text import to_unicode 20 21 21 22 from tracspamfilter.api import IFilterStrategy, N_ 22 23 … … 81 82 check.validate_registration(req) 82 83 except RegistrationError as e: 83 84 karma -= abs(self.karma_points) 84 msg = e.message.replace('\n', '') 85 args = e.msg_args 86 if args: 87 msg = msg % args 88 msg.replace('<b>', '*').replace('</b>', '*') 85 msg = striptags(to_unicode(e)) 89 86 self.log.debug("Registration check returned %s", msg) 90 87 checks.append('%s: %s' % (check.__class__.__name__, msg)) 91 88 except Exception as e:
Attachments (0)
Change History (3)
comment:1 by , 18 months ago
comment:2 by , 18 months ago
At least, the conversion to bold for <b>/</b> doesn't work. Also, msg % args is not needed because accountmanagerplugin currently creates the exception with formatted message at all places.
- msg = msg % args - msg.replace('<b>', '*').replace('</b>', '*') + msg = msg.replace('<b>', '*').replace('</b>', '*')
comment:3 by , 18 months ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
In r17824.
I used mainly your original patch. Seems accountmanager changed a bit after I first implemented this.
Note:
See TracTickets
for help on using tickets.



Did you check your patch beside "compiles"? As far as I can see it will loose argument expansion and also conversion to bold for <b>. I think it's only necessary to convert e.message to unicode.
tracspamfilter/filters/registration.py
e.message.replace('\n', '')