Edgewall Software
Modify

Opened 14 years ago

Closed 14 years ago

Last modified 7 years ago

#3011 closed defect (fixed)

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

Reported by: almando@… Owned by: Christian Boos
Priority: normal Milestone: 0.11
Component: ticket system Version: 0.9.6
Severity: normal Keywords:
Cc: Branch:
Release Notes:
API Changes:
Internal 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 (0)

Change History (8)

comment:1 by Christian Boos, 14 years ago

Component: generalticket system
Milestone: 0.10
Owner: changed from Jonas Borgström to Christian Boos
Status: newassigned

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 by Christopher Lenz, 14 years ago

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

comment:3 by Christian Boos, 14 years ago

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 by Christopher Lenz, 14 years ago

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

comment:5 by Christian Boos, 14 years ago

Resolution: fixed
Status: assignedclosed

Done in r3122.

comment:6 by anonymous, 14 years ago

Resolution: fixed
Status: closedreopened
Version: 0.9.40.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 by Christian Boos, 14 years ago

Milestone: 0.100.11
Status: reopenednew

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 by Christian Boos, 14 years ago

Resolution: fixed
Status: newclosed

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.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Christian Boos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Christian Boos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.