Edgewall Software
Modify

Opened 5 months ago

Closed 5 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

     
    1616
    1717from trac.config import BoolOption, IntOption
    1818from trac.core import Component, ExtensionPoint, implements
    19 from trac.util.html import tag
     19from trac.util.html import striptags, tag
     20from trac.util.text import to_unicode
    2021
    2122from tracspamfilter.api import IFilterStrategy, N_
    2223
     
    8182                        check.validate_registration(req)
    8283                except RegistrationError as e:
    8384                    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))
    8986                    self.log.debug("Registration check returned %s", msg)
    9087                    checks.append('%s: %s' % (check.__class__.__name__, msg))
    9188                except Exception as e:

Attachments (0)

Change History (3)

comment:1 by Dirk Stöcker, 5 months ago

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

     
    8181                        check.validate_registration(req)
    8282                except RegistrationError as e:
    8383                    karma -= abs(self.karma_points)
    84                     msg = e.message.replace('\n', '')
     84                    msg = unicode(e.message).replace('\n', '')
    8585                    args = e.msg_args
    8686                    if args:
    8787                        msg = msg % args

comment:2 by Jun Omae, 5 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 Dirk Stöcker, 5 months ago

Resolution: fixed
Status: newclosed

In r17824.

I used mainly your original patch. Seems accountmanager changed a bit after I first implemented this.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Dirk Stöcker.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Dirk Stöcker to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.