Edgewall Software

Ticket #5968 (closed defect: fixed)

Opened 15 months ago

Last modified 5 months ago

InterTrac links with blank target don't work even though TracLinks of the same form do

Reported by: ben@… Owned by: cboos
Priority: normal Milestone: 0.11.1
Component: wiki system Version:
Severity: normal Keywords: intertrac
Cc: kevin@…

Description (last modified by cboos) (diff)

Inside a wiki page [wiki: blah] works to link to the top level of the wiki; however, [trac:wiki: blah] doesn't work (I get a '"wiki:" is not a TracLinks' error).

If I turn intertrac compat mode, then the link works (because the originating Trac instance formats the link).

Attachments

t5968.patch (3.4 KB) - added by cboos 15 months ago.
Same change than the inlined diff, plus some tests and a cosmetic change for the link title when there's no target.

Change History

  Changed 15 months ago by cboos

  • keywords intertrac added
  • owner changed from jonas to cboos
  • status changed from new to assigned
  • component changed from general to wiki
  • milestone set to 0.11

Suggesting:

  • trac:wiki or [trac:wiki] for linking to the Wiki module
  • [trac:] for linking to the toplevel (#4314)

Which can be implemented by removing a few checks in the intertrac module:

  • trac/wiki/intertrac.py

     
    4141 
    4242    def process_request(self, req): 
    4343        link = req.args.get('link', '') 
    44         if not link: 
    45             raise TracError('No TracLinks given') 
    4644        link_elt = extract_link(Context(self.env, req), link) 
    4745        if isinstance(link_elt, Element): 
    4846            href = link_elt.attrib.get('href') 
    49             if href: 
    50                 req.redirect(href) 
    51         raise TracError('"%s" is not a TracLinks' % link) 
     47        else: 
     48            href = req.href(link) 
     49        req.redirect(href) 
    5250 
    53  
    5451    # IWikiMacroProvider methods 
    5552 
    5653    def get_macros(self): 

Invalid InterTrac links will instead trigger a "No handler matched request to <link>" error.

Changed 15 months ago by cboos

Same change than the inlined diff, plus some tests and a cosmetic change for the link title when there's no target.

  Changed 13 months ago by cboos

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

Patch applied in [6137].

  Changed 6 months ago by Kevin Gabbert

  • status changed from closed to reopened
  • resolution fixed deleted

I'm having this same exact problem in .11rc1 (windows). The most recent download at this time

was there a regression?

the exact error I get is:

Internal Error

"wiki:" is not a TracLinks

  Changed 6 months ago by kevin@…

  • cc kevin@… added

follow-up: ↓ 6   Changed 6 months ago by cboos

  • description modified (diff)

What is currently implemented is the suggestion presented in comment:1, i.e. [<intertrac-prefix>:wiki].

However, I agree that [<intertrac-prefix>:wiki:] could be normalized to the same target.

I use this opportunity to add a reminder about another problem with InterTrac links:

[trac:SpamFilter SpamFilter],
[trac:SpamFilter the SpamFilter]

renders as:

(while the second works as expected, the first also shows the trac: prefix when it shouldn't)

in reply to: ↑ 5 ; follow-up: ↓ 7   Changed 6 months ago by osimons

Replying to cboos:

(while the second works as expected, the first also shows the trac: prefix when it shouldn't)

That would be me in [6417], and it only occurs when the target and label are identical. Problem is that the _make_link() code does not know the differenence as the _lhref_formatter() sets label to target if no label is set before passing on to rendering.

The reason for wanting the prefix was to treat intertrac/wiki links like any other external link like http:// and similar. The default behaviour without label should include the external target.

I haven't looked into what that match argument passed in to _make_link() actually contains, but if that allows me to identify 'no label' it would just be a matter of changing if label == target: to something looking into the match object instead (formatter.py).

in reply to: ↑ 6   Changed 6 months ago by osimons

Replying to osimons:

Replying to cboos:

(while the second works as expected, the first also shows the trac: prefix when it shouldn't)

That would be me in [6417], and it only occurs when the target and label are identical. Problem is that the _make_link() code does not know the differenence as the _lhref_formatter() sets label to target if no label is set before passing on to rendering.

Seems match contains the full wiki link text. Using some string trickery, it should then be possible to detect if there is no actual label set when the strings are identical. This works when testing your examples:

  • trac/wiki/formatter.py

     
    390390            else: 
    391391                return olabel or otarget 
    392392        else: 
    393             if label == target: 
     393            if label == target \ 
     394                    and match[match.find(label):].rstrip(']') == label: 
    394395                # add ns for Inter* links when nothing is set 
    395396                label = ns+':'+label 
    396397            return self._make_intertrac_link(ns, target, label) or \ 

follow-up: ↓ 9   Changed 6 months ago by cboos

What about passing the fullmatch object to _make_link and look for the 'label'group? If present, then always use it, otherwise use ns:label because it will be either a shref or a lhref with no label set. That would be cleaner I think.

in reply to: ↑ 8   Changed 5 months ago by osimons

Replying to cboos:

What about passing the fullmatch object to _make_link...

Yup. Makes more sense than trying to reparse it again. Committed in [7238:7239] for 0.11 and trunk.

That concludes the detour from the main ticket topic, I guess.

  Changed 5 months ago by cboos

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

Last fix done in [7312].

Add/Change #5968 (InterTrac links with blank target don't work even though TracLinks of the same form do)

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.