Modify

Opened 6 years ago

Closed 9 months ago

#3983 closed defect (fixed)

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 (13)

comment:1 Changed 6 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 6 years ago by anonymous

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

comment:3 Changed 6 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 5 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 5 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 5 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 3 years ago by osimons

  • Cc hasienda added; anonymous removed
  • 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 3 years ago by rjollos

  • Keywords ListTagged query added

comment:9 Changed 3 years ago by hasienda

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

comment:10 Changed 3 years 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 3 years 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 2 years ago by hasienda

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

comment:13 Changed 9 months ago by hasienda

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

In 13815:

TagsPlugin: Completing preparation for v0.7 release.

Availability of that code as stable, tagged release
closes #2429, #3359, #3610, #3624, #3677, #3754, #3864, #3947, #3983, #4078, #4277, #4503, #4799, #5523, #7787, #7857, #8638, #9057, #9058, #9059, #9060, #9061, #9062, #9063, #9149, #9210, #9521, #9630, #9636, #10032, #10416, #10636, #11096, #11147, #11152, #11274, #11302, #11658 and #11659.

Additionally there are some issues and enhancement requests showing progress,
but known to require more work to resolve them satisfactorily, specifically
refs #2804, #4200, #8747 and #9064.

Thanks to all contributors and followers, that enabled and encouraged a good
portion of this development work.

Add Comment

Modify Ticket

Action
as closed The owner will remain hasienda.
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.