Ticket #2855 (closed defect: fixed)

Opened 5 months ago

Last modified 2 months ago

Trouble handling regular expressions

Reported by: creanium Assigned to: 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

asterisk.patch (0.5 kB) - added by creanium on 04/03/08 21:09:45.
Patch to wiki.py that now allows it to properly handle asterisks in the subscriptions
astrisk.patch (1.4 kB) - added by doki_pen on 06/23/08 13:59:21.
move glob to regex code to query instead of save to avoid duplicate replacements

Change History

04/03/08 21:09:45 changed by creanium

  • attachment asterisk.patch added.

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

06/23/08 13:29:14 changed 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.

06/23/08 13:59:21 changed by doki_pen

  • attachment astrisk.patch added.

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

06/23/08 13:59:53 changed by doki_pen

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

07/21/08 08:38:36 changed by doki_pen

  • status changed from new to closed.
  • resolution set to fixed.

fixed in r4046


Add/Change #2855 (Trouble handling regular expressions)




Change Properties
Action