Edgewall Software

Ticket #3011 (closed defect: fixed)

Opened 3 years ago

Last modified 2 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:

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

Changed 3 years ago by cboos

  • owner changed from jonas to cboos
  • status changed from new to assigned
  • component changed from general to ticket system
  • milestone set to 0.10

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

Changed 3 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.

Changed 3 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?

Changed 3 years ago by cmlenz

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

Changed 3 years ago by cboos

  • status changed from assigned to closed
  • resolution set to fixed

Done in r3122.

Changed 2 years ago by anonymous

  • status changed from closed to reopened
  • version changed from 0.9.4 to 0.9.6
  • resolution fixed deleted

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.

Changed 2 years ago by cboos

  • status changed from reopened to new
  • milestone changed from 0.10 to 0.11

With 0.10, it doesn't break the timeline: ticket:123,456 -> ticket: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.

Changed 2 years ago by cboos

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

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.

Add/Change #3011 (Trac crash on bad text on a comment of a changeset.)

Author



Change Properties
<Author field>
Action
as closed
Next status will be 'reopened'
to The owner will change from cboos. Next status will be 'closed'
 
Note: See TracTickets for help on using tickets.