Edgewall Software
Modify

Ticket #3011 (closed defect: fixed)

Opened 6 years ago

Last modified 6 years ago

Trac crash on bad text on a comment of a changeset.

Reported by: almando@… Owned by: cboos
Priority: normal Milestone: 0.11
Component: ticket system Version: 0.9.6
Severity: normal Keywords:
Cc:
Release Notes:
API Changes:

Description

When you create a changeset and the comment of the changeset references a ticket like this below:

ticket:#131

if u write as showed above without spaces. trac guive error showing timeline and the source.
look traceback below

Python traceback

Traceback (most recent call last):
  File "/usr/lib/python2.4/site-packages/trac/web/modpython_frontend.py", line 206, in handler
    dispatch_request(mpr.path_info, mpr, env)
  File "/usr/lib/python2.4/site-packages/trac/web/main.py", line 139, in dispatch_request
    dispatcher.dispatch(req)
  File "/usr/lib/python2.4/site-packages/trac/web/main.py", line 107, in dispatch
    resp = chosen_handler.process_request(req)
  File "/usr/lib/python2.4/site-packages/trac/versioncontrol/web_ui/browser.py", line 102, in process_request
    self._render_directory(req, repos, node, rev)
  File "/usr/lib/python2.4/site-packages/trac/versioncontrol/web_ui/browser.py", line 134, in _render_directory
    changes = get_changes(self.env, repos, [i['rev'] for i in info])
  File "/usr/lib/python2.4/site-packages/trac/versioncontrol/web_ui/util.py", line 35, in get_changes
    shortlog = wiki_to_oneliner(message, env, db, shorten=True)
  File "/usr/lib/python2.4/site-packages/trac/wiki/formatter.py", line 749, in wiki_to_oneliner
    OneLinerFormatter(env, absurls, db).format(wikitext, out, shorten)
  File "/usr/lib/python2.4/site-packages/trac/wiki/formatter.py", line 685, in format
    result = re.sub(self.rules, self.replace, result)
  File "/usr/lib/python2.4/sre.py", line 142, in sub
    return _compile(pattern, 0).sub(repl, string, count)
  File "/usr/lib/python2.4/site-packages/trac/wiki/formatter.py", line 221, in replace
    return getattr(self, '_' + itype + '_formatter')(match, fullmatch)
  File "/usr/lib/python2.4/site-packages/trac/wiki/formatter.py", line 271, in _shref_formatter
    return self._make_link(ns, target, match, match)
  File "/usr/lib/python2.4/site-packages/trac/wiki/formatter.py", line 295, in _make_link
    util.escape(label, False))
  File "/usr/lib/python2.4/site-packages/trac/ticket/api.py", line 159, in _format_link
    (target,))
IntegrityError: ERROR:  invalid input syntax for integer: "#131"

SELECT summary,status FROM ticket WHERE id='#131'


Attachments

Change History

comment:1 Changed 6 years ago by cboos

  • Component changed from general to ticket system
  • Milestone set to 0.10
  • Owner changed from jonas to cboos
  • Status changed from new to assigned

Well, yes, there shouldn't be an exception in this situation.

Index: api.py
===================================================================
--- api.py	(revision 3118)
+++ api.py	(working copy)
@@ -160,17 +160,20 @@
                                                          fullmatch)
         if intertrac:
             return intertrac
-        cursor = formatter.db.cursor()
-        cursor.execute("SELECT summary,status FROM ticket WHERE id=%s",
-                       (target,))
-        row = cursor.fetchone()
-        if row:
-            return html.A(class_='%s ticket' % row[1],
-                          title=shorten_line(row[0]) + ' (%s)' % row[1],
-                          href=formatter.href.ticket(target))[label]
-        else:
-            return html.A(class_='missing ticket', rel='nofollow',
-                          href=formatter.href.ticket(target))[label]
+        try:
+            target = int(target.lstrip('#'))
+            cursor = formatter.db.cursor()
+            cursor.execute("SELECT summary,status FROM ticket WHERE id=%s",
+                           (str(target),))
+            row = cursor.fetchone()
+            if row:
+                return html.A(class_='%s ticket' % row[1],
+                              title=shorten_line(row[0]) + ' (%s)' % row[1],
+                              href=formatter.href.ticket(target))[label]
+        except ValueError:
+            pass
+        return html.A(class_='missing ticket', rel='nofollow',
+                      href=formatter.href.ticket(target))[label]
 
     # ISearchSource methods

This does two things:

  • tolerate ticket:#123 to be an alias for ticket:123
  • create a missing ticket link when target is not a number or a '#' followed by a number

comment:2 Changed 6 years ago by cmlenz

Tolerating ticket:#123 isn't a good idea… where would you stop? The rules should remain as simple as possible IMO.

comment:3 Changed 6 years ago by cboos

Ok.

I would also like to take this opportunity to split up a bit
the unit-tests for wiki formatting (each IWikiSyntaxProvider
should be able to provide its own tests, instead of putting them
in the big melting pot…)

Are you OK with this?

comment:4 Changed 6 years ago by cmlenz

Absolutely… and no need to split the input/output off into text files either, as they are pretty small.

comment:5 Changed 6 years ago by cboos

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

Done in r3122.

comment:6 Changed 6 years ago by anonymous

  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Version changed from 0.9.4 to 0.9.6

TortoiseSVN&co allow anything to be entered in the ticket nr field, so Trac should handle anything without throwing exceptions when parsing those commit messages.

We use Trac 0.9.6 and for many tickets we have entered a comma separated list of ticket numbers like "123,456". Doing this breaks the "Timeline" page.

I know it's a better practice to always check in just one change for one ticket, but life is never that simple, is it? So it would be great if you could also handle lists.

comment:7 Changed 6 years ago by cboos

  • Milestone changed from 0.10 to 0.11
  • Status changed from reopened to new

With 0.10, it doesn't break the timeline: ticket:123,456ticket:123,456.

However, I'll leave the ticket open for the list idea.
I imagine that we could "translate" ticket:123,456 into a kind of custom query matching those two tickets.

comment:8 Changed 6 years ago by cboos

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

Implemented in r4239.

Now the TortoiseSVN's bugtraq:url property could be configured to point to one of these:

  • <your-trac-url>/intertrac/ticket:%BUGID%
  • <your-trac-url>/query?id=%BUGID%

In addition, the bugtraq:logregex property could be set to:

(?:ticket:|#)\d+(?:[-:]\d+)?(?:,\d+(?:[-:]\d+)?)*
\d+(?:[-:]\d+)?(?:,\d+(?:[-:]\d+)?)*

in order to match the regexps now used by Trac.

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
to The owner will be changed from cboos. Next status will be 'closed'
Author


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

 
Note: See TracTickets for help on using tickets.