Edgewall Software
Modify

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#11302 closed defect (fixed)

error with relative link to parent wiki page from an attachment description

Reported by: Christian Boos Owned by: Christian Boos
Priority: normal Milestone: 1.0.2
Component: wiki system Version: 1.0-stable
Severity: normal Keywords:
Cc: Ryan J Ollos Branch:
Release Notes:

Fix a glitch making it impossible to edit a page if a description of an attachment contained some forms of relative link.

API Changes:
Internal Changes:

Description

How to Reproduce

While doing a GET operation on /wiki/WikiStart, Trac issued an internal error.

The link in question had the form [./@1#TheId].

I stumbled upon this error once I started to edit the page. The attachment operation itself and the wiki view was working fine.

Request parameters:

{'action': u'edit', 'page': u'WikiStart'}

User agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.37 Safari/537.36

System Information

System information not available

Enabled Plugins

Plugin information not available

Python Traceback

Traceback (most recent call last):
  File "c:\Trac\repos\1.0-stable\trac\web\main.py", line 497, in _dispatch_request
    dispatcher.dispatch(req)
  File "c:\Trac\repos\1.0-stable\trac\web\main.py", line 233, in dispatch
    content_type)
  File "c:\Trac\repos\1.0-stable\trac\web\chrome.py", line 1029, in render_template
    encoding='utf-8')
  File "c:\Dev\Python273\lib\site-packages\genshi-0.6.1-py2.7.egg\genshi\core.py", line 183, in render
    return encode(generator, method=method, encoding=encoding, out=out)
  File "c:\Dev\Python273\lib\site-packages\genshi-0.6.1-py2.7.egg\genshi\output.py", line 58, in encode
    for chunk in iterator:
  File "c:\Dev\Python273\lib\site-packages\genshi-0.6.1-py2.7.egg\genshi\output.py", line 350, in __call__
    for kind, data, pos in stream:
  File "c:\Dev\Python273\lib\site-packages\genshi-0.6.1-py2.7.egg\genshi\output.py", line 829, in __call__
    for kind, data, pos in stream:
  File "c:\Dev\Python273\lib\site-packages\genshi-0.6.1-py2.7.egg\genshi\output.py", line 669, in __call__
    for kind, data, pos in stream:
  File "c:\Dev\Python273\lib\site-packages\genshi-0.6.1-py2.7.egg\genshi\output.py", line 774, in __call__
    for kind, data, pos in chain(stream, [(None, None, None)]):
  File "c:\Dev\Python273\lib\site-packages\genshi-0.6.1-py2.7.egg\genshi\output.py", line 594, in __call__
    for ev in stream:
  File "c:\Dev\Python273\lib\site-packages\genshi-0.6.1-py2.7.egg\genshi\core.py", line 288, in _ensure
    for event in stream:
  File "c:\Dev\Python273\lib\site-packages\genshi-0.6.1-py2.7.egg\genshi\core.py", line 288, in _ensure
    for event in stream:
  File "c:\Trac\repos\1.0-stable\trac\web\chrome.py", line 1167, in _strip_accesskeys
    for kind, data, pos in stream:
  File "c:\Dev\Python273\lib\site-packages\genshi-0.6.1-py2.7.egg\genshi\core.py", line 288, in _ensure
    for event in stream:
  File "c:\Trac\repos\1.0-stable\trac\web\chrome.py", line 1156, in _generate
    for kind, data, pos in stream:
  File "c:\Dev\Python273\lib\site-packages\genshi-0.6.1-py2.7.egg\genshi\template\base.py", line 617, in _include
    for event in stream:
  File "c:\Dev\Python273\lib\site-packages\genshi-0.6.1-py2.7.egg\genshi\template\markup.py", line 378, in _match
    ctxt, start=idx + 1, **vars):
  File "c:\Dev\Python273\lib\site-packages\genshi-0.6.1-py2.7.egg\genshi\template\markup.py", line 378, in _match
    ctxt, start=idx + 1, **vars):
  File "c:\Dev\Python273\lib\site-packages\genshi-0.6.1-py2.7.egg\genshi\template\markup.py", line 326, in _match
    for event in stream:
  File "c:\Dev\Python273\lib\site-packages\genshi-0.6.1-py2.7.egg\genshi\template\base.py", line 557, in _flatten
    for kind, data, pos in stream:
  File "c:\Dev\Python273\lib\site-packages\genshi-0.6.1-py2.7.egg\genshi\core.py", line 288, in _ensure
    for event in stream:
  File "c:\Dev\Python273\lib\site-packages\genshi-0.6.1-py2.7.egg\genshi\path.py", line 588, in _generate
    subevent = next()
  File "c:\Dev\Python273\lib\site-packages\genshi-0.6.1-py2.7.egg\genshi\template\base.py", line 617, in _include
    for event in stream:
  File "c:\Dev\Python273\lib\site-packages\genshi-0.6.1-py2.7.egg\genshi\template\markup.py", line 315, in _strip
    event = next()
  File "c:\Dev\Python273\lib\site-packages\genshi-0.6.1-py2.7.egg\genshi\template\base.py", line 557, in _flatten
    for kind, data, pos in stream:
  File "c:\Dev\Python273\lib\site-packages\genshi-0.6.1-py2.7.egg\genshi\core.py", line 288, in _ensure
    for event in stream:
  File "c:\Dev\Python273\lib\site-packages\genshi-0.6.1-py2.7.egg\genshi\path.py", line 588, in _generate
    subevent = next()
  File "c:\Dev\Python273\lib\site-packages\genshi-0.6.1-py2.7.egg\genshi\template\base.py", line 617, in _include
    for event in stream:
  File "c:\Dev\Python273\lib\site-packages\genshi-0.6.1-py2.7.egg\genshi\template\markup.py", line 315, in _strip
    event = next()
  File "c:\Dev\Python273\lib\site-packages\genshi-0.6.1-py2.7.egg\genshi\template\base.py", line 577, in _flatten
    result = _eval_expr(data, ctxt, vars)
  File "c:\Dev\Python273\lib\site-packages\genshi-0.6.1-py2.7.egg\genshi\template\base.py", line 289, in _eval_expr
    retval = expr.evaluate(ctxt)
  File "c:\Dev\Python273\lib\site-packages\genshi-0.6.1-py2.7.egg\genshi\template\eval.py", line 178, in evaluate
    return eval(self.code, _globals, {'__data__': data})
  File "c:\Trac\repos\1.0-stable\trac\templates\list_of_attachments.html", line 34, in <Expression u'wiki_to_oneliner(context, attachment.description)'>
    <q py:if="compact and attachment.description">${wiki_to_oneliner(context, attachment.description)}</q>
  File "c:\Trac\repos\1.0-stable\trac\wiki\formatter.py", line 1553, in format_to_oneliner
    return InlineHtmlFormatter(env, context, wikidom).generate(shorten)
  File "c:\Trac\repos\1.0-stable\trac\wiki\formatter.py", line 1529, in generate
    shorten)
  File "c:\Trac\repos\1.0-stable\trac\wiki\formatter.py", line 1385, in format
    result = re.sub(self.wikiparser.rules, self.replace, result)
  File "c:\Dev\Python273\lib\re.py", line 151, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "c:\Trac\repos\1.0-stable\trac\wiki\formatter.py", line 1201, in replace
    replacement = self.handle_match(fullmatch)
  File "c:\Trac\repos\1.0-stable\trac\wiki\formatter.py", line 1197, in handle_match
    return internal_handler(match, fullmatch)
  File "c:\Trac\repos\1.0-stable\trac\wiki\formatter.py", line 591, in _lhref_formatter
    return self._make_lhref_link(match, fullmatch, rel, ns, target, label)
  File "c:\Trac\repos\1.0-stable\trac\wiki\formatter.py", line 621, in _make_lhref_link
    label, fullmatch)
  File "c:\Trac\repos\1.0-stable\trac\wiki\formatter.py", line 656, in _make_link
    return self._make_intertrac_link(ns, target, label) or \
  File "c:\Trac\repos\1.0-stable\trac\wiki\formatter.py", line 661, in _make_intertrac_link
    res = self.get_intertrac_url(ns, target)
  File "c:\Trac\repos\1.0-stable\trac\wiki\formatter.py", line 667, in get_intertrac_url
    url = intertrac.get(ns + '.url')
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

This happens because context in the template data was the default (toplevel) context, and that was what was used by the list_of_attachments included template.

Fix and test follows.

Attachments (0)

Change History (8)

comment:1 by Christian Boos, 11 years ago

Status: newassigned

comment:2 by Remy Blank, 11 years ago

This has probably nothing to do with this bug, but is the trailing / necessary? I.e. isn't the canonical representation of that link [.@1#TheId]?

in reply to:  2 comment:3 by Christian Boos, 11 years ago

Replying to rblank:

… isn't the canonical representation of that link [.@1#TheId]?

That would be another bug… [.@1#TheId] isn't detected as a relative wiki link, whereas [[.@1#TheId]] is.

Note

Note that [.#Note note] (note) and even [.?version=3#Note note at version 3] (note at version 3) work not only for Wiki pages but also for tickets.

comment:4 by Christian Boos, 11 years ago

Resolution: fixed
Status: assignedclosed

Applied in r12157, merged into trunk in r12158.

comment:5 by Ryan J Ollos, 11 years ago

# self._tester.go_to_wiki(pagename + '?action=edit')
# tc.url has trouble with that...

In the time since you first generated your patch, I encountered and committed a change for that issue in [12152]. Now, the following refactoring is possible:

  • trac/wiki/tests/functional.py

    diff --git a/trac/wiki/tests/functional.py b/trac/wiki/tests/functional.py
    index a021cae..df008ae 100755
    a b class RegressionTestTicket10957(FunctionalTwillTestCaseSet  
    316316class RegressionTestTicket11302(FunctionalTwillTestCaseSetup):
    317317    def runTest(self):
    318318        """Test for regression of http://trac.edgewall.org/ticket/11302"""
    319         pagename = random_unique_camel()
    320         self._tester.create_wiki_page(pagename)
     319        pagename = self._tester.create_wiki_page()
    321320        attachment = self._tester.attach_file_to_wiki(
    322321            pagename, description="illustrates [./@1#point1]")
    323         # self._tester.go_to_wiki(pagename + '?action=edit')
    324         # tc.url has trouble with that...
    325         tc.go(self._tester.url + '/wiki/' + pagename + '?action=edit')
     322        self._tester.go_to_wiki(pagename + '?action=edit')
    326323        tc.find(r'illustrates <a class="wiki"'
    327324                r' href="/wiki/%s\?version=1#point1">@1</a>' % pagename)

If no issues are spotted with the change, shall I commit it?

comment:6 by Ryan J Ollos, 11 years ago

Cc: Ryan J Ollos added

comment:7 by Christian Boos, 11 years ago

tc.url(re.escape(url)), ah sure, makes sense. Please apply your follow-up.

comment:8 by Ryan J Ollos, 11 years ago

Thanks, committed to 1.0-stable in [12162] and merged to trunk in [12163].

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.