Modify

Opened 6 years ago

Closed 6 years ago

#2855 closed defect (fixed)

Trouble handling regular expressions

Reported by: creanium Owned by: ixokai
Priority: normal Component: AnnouncerPlugin
Severity: normal Keywords:
Cc: Trac Release: 0.11

Description

In testing out the installation, I wanted to try out global Wiki subscriptions as we have a Trac instance to which we post meeting announcements and Minutes and would like messages to always go out.

I went into my preferences and entered a single Wiki subscription: * and clicked save.

The page reloaded and I noticed what I entered as simply "*" was now ".*?". Cool, I thought, it just converted it to regular expression, no biggy.

When I saved the page again, however, what was previously ".*?" was now "..*??". Uh oh, a replace error.

So I went in and fixed it again, to just "*".

Then I tried creating a new Wiki page to see if I would get notified.

No email.

I checked the Trac log, and the following was in it:

2008-04-03 18:45:05,364 Trac[api] ERROR: AnnouncementSystem failed.
Traceback (most recent call last):
  File "build/bdist.linux-i686/egg/announcerplugin/api.py", line 355, in _real_send
  File "build/bdist.linux-i686/egg/announcerplugin/api.py", line 355, in <genexpr>
  File "/usr/local/lib/python2.5/site-packages/AnnouncerPlugin-0.2-py2.5.egg/announcerplugin/subscribers/wiki.py", line 24, in get_subscriptions_for_event
    for name, authenticated in self._get_membership(page.name):
  File "/usr/local/lib/python2.5/site-packages/AnnouncerPlugin-0.2-py2.5.egg/announcerplugin/subscribers/wiki.py", line 47, in _get_membership
    if re.match(pat, name):
  File "/usr/local/lib/python2.5/re.py", line 137, in match
    return _compile(pattern, flags).match(string)
  File "/usr/local/lib/python2.5/re.py", line 241, in _compile
    raise error, v # invalid expression
error: nothing to repeat

Okay, I added a line of debug output to see what it was trying to RegEx match.

Trac[wiki] DEBUG: Checking re.match(*, WikiStart)

Oh no wonder, so I stepped through wiki.py and found where the replacements were supposed to be happening and realized the escape character handler was parsing in the wrong order.

So, attached is the patch I did that on wiki.py that now allows a * subscription to work.

Attachments (2)

asterisk.patch (523 bytes) - added by creanium 6 years ago.
Patch to wiki.py that now allows it to properly handle asterisks in the subscriptions
astrisk.patch (1.4 KB) - added by doki_pen 6 years ago.
move glob to regex code to query instead of save to avoid duplicate replacements

Download all attachments as: .zip

Change History (5)

Changed 6 years ago by creanium

Patch to wiki.py that now allows it to properly handle asterisks in the subscriptions

comment:1 Changed 6 years ago by doki_pen

I still think this is a weak solution, as if you save multiple times, the '*' keeps getting expanded.

  • = .* .* = .. .. = ...*

big trouble.

The substitution should happen right before the evaluation of the wiki page name, and kept in glob format in the DB. My patch is still weak, but a little better. I'm willing to bet there is a python library to match globs. Or you could just use regexes instead.

Changed 6 years ago by doki_pen

move glob to regex code to query instead of save to avoid duplicate replacements

comment:2 Changed 6 years ago by doki_pen

Sorry for the bad spelling.. lol.
attachment: astrisk.patch

comment:3 Changed 6 years ago by doki_pen

  • Resolution set to fixed
  • Status changed from new to closed

fixed in r4046

Add Comment

Modify Ticket

Action
as closed .
The resolution will be deleted. Next status will be 'reopened'.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.