Modify

Opened 5 years ago

Last modified 7 months ago

#3983 new defect

ListTagged broken for tags starting with 'or'

Reported by: markh@… Owned by: hasienda
Priority: normal Component: TagsPlugin
Severity: normal Keywords: ListTagged query
Cc: jun66j5 Trac Release: 0.11

Description

New Trac 0.11 install with TagsPlugin, TracAccountManager, Pygments, and TracTocMacro. I've created Tracs with both MySQL (5.1) and SQLite backends to verify it wasn't the database.

I was tagging entries with several tags, such as 'database docs howto debian4 oracle', and using ListTagged() works or all of the tags but 'oracle', which returns an empty list. I then tried 'orwich' as a tag to test, as well as 'racle', the former failing to show up and the latter working. Subsequent tests show that other tags beginning with 'or' fail to show up in a ListTagged list.

Attachments (0)

Change History (12)

comment:1 Changed 5 years ago by BryanTsai

  • Owner changed from athomas to BryanTsai
  • Status changed from new to assigned

We have also encountered the same problem here. tag 'oracle' does not work on our Trac site.

comment:2 Changed 5 years ago by anonymous

  • Owner changed from BryanTsai to athomas
  • Status changed from assigned to new

comment:3 Changed 5 years ago by BryanTsai

It seems to be an regex problem. I've made the following change on my environment and it worked fine so far:

Index: tractags/query.py
===================================================================
--- tractags/query.py   (revision 4775)
+++ tractags/query.py   (working copy)
@@ -140,7 +140,7 @@

     _tokenise_re = re.compile(r"""
         (?P<not>-)|
-        (?P<or>or)|
+        (?P<or>or\s+)|
         \"(?P<dquote>(?:\\.|[^\"])*)\"|
         '(?P<squote>(?:\\.|[^'])*)'|
         (?P<startsub>\()|

comment:4 follow-up: Changed 3 years ago by otaku42

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

(In [7374]) Fix bug where tags starting with "or", when passed as parameter to the
ListTagged macro, did not return any result. Thanks to BryanTsai for
the patch. Fixes #3983.

comment:5 in reply to: ↑ 4 Changed 3 years ago by otaku42

Replying to otaku42:

(In [7374]) Fix bug where tags starting with "or", when passed as parameter to the
ListTagged macro, did not return any result. Thanks to BryanTsai for
the patch. Fixes #3983.

Guess I had a bad day:

I accidentally committed stuff to the tagged release v0.6 rather than to trunk, which of course was wrong. I'll thus roll back r7374 and re-apply the patch to trunk instead.

comment:6 Changed 3 years ago by otaku42

(In [7378]) Fix bug where tags starting with "or", when passed as parameter to the
ListTagged macro, did not return any result. Thanks to BryanTsai for
the patch. Fixes #3983.

comment:7 Changed 21 months ago by osimons

  • Cc hasienda added
  • Resolution fixed deleted
  • Status changed from closed to reopened

I'll reopen this actually, as it breaks the tests for the plugin. "Which tests?", I hear you say... :-) Well, query.py actually comes with doctests, and this one breaks:

----------------------------------------------------------------------
File "trunk/tractags/query.py", line 380, in tractags.query.Query._tokenise
Failed example:
    q._tokenise('one or two')
Expected:
    [(1, 'one'), (4, 'or'), (1, 'two')]
Got:
    [(1, 'one'), (4, 'or '), (1, 'two')]

----------------------------------------------------------------------

Either the fix or the test is wrong.

comment:8 Changed 21 months ago by rjollos

  • Keywords ListTagged query added

comment:9 Changed 21 months ago by hasienda

See #3624 for another issue related to parsing/quoting.

comment:10 Changed 20 months ago by hasienda

  • Cc jun66j5 added; hasienda removed

The results created with the patch applied are not exactly right, so it is certainly not awfully wrong, but still wrong.

I had a lookahead assertion in mind like this:

  • tagsplugin/trunk/tractags/query.py

    a b  
    140140 
    141141    _tokenise_re = re.compile(r""" 
    142142        (?P<not>-)| 
    143         (?P<or>or\s+)| 
     143        (?P<or>or(?=\s+))| 
    144144        \"(?P<dquote>(?:\\.|[^\"])*)\"| 
    145145        '(?P<squote>(?:\\.|[^'])*)'| 
    146146        (?P<startsub>\()| 

but later spotted Jun Omae's solution included in his patch for #9057, that looks more elegant to my eyes:

  • tagsplugin/trunk/tractags/query.py

    a b  
    140140 
    141141    _tokenise_re = re.compile(r""" 
    142142        (?P<not>-)| 
    143         (?P<or>or\s+)| 
     143        (?P<or>or)\s+| 
    144144        \"(?P<dquote>(?:\\.|[^\"])*)\"| 
    145145        '(?P<squote>(?:\\.|[^'])*)'| 
    146146        (?P<startsub>\()| 

Thank you Odd for your assistance with the test infrastructure for this plugin. Obviously this is already leading to improved code quality.

comment:11 Changed 20 months ago by hasienda

(In [10784]) TagsPlugin: Correct tokenization for the 'or' operator, refs #3983 and #9057.

The regular expression introduced in [7378] is corrected now for tokenization
to finally match expectations with respect to the particular behavior:
All included tests pass now. Thanks to Jun Omae for the patch.

comment:12 Changed 7 months ago by hasienda

  • Owner changed from athomas to hasienda
  • Status changed from reopened to new

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as new .
as The resolution will be set. Next status will be 'closed'.
to The owner will be changed from hasienda. Next status will be 'new'.
The owner will be changed from hasienda to anonymous. Next status will be 'assigned'.
Author


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

 
Note: See TracTickets for help on using tickets.