Edgewall Software

Ticket #3643 (closed enhancement: fixed)

Opened 2 years ago

Last modified 2 years ago

InterWiki Link Colon Esacape

Reported by: trac@… Owned by: cboos
Priority: low Milestone: 0.10
Component: wiki system Version: devel
Severity: minor Keywords: interwiki
Cc:

Description

How about providing some kind of escape mechanism for colons in InterWiki links.

Maybe something a little less horrible than using the following:

t = target.replace("!:", "\x00")
args = t.split(':')
args = [argn.replace("\x00", ":") for argn in args]

instead of just:

args = target.split(':')

in interwiki.py.

(Sorry, I'm just learning Python.)

Attachments

Change History

  Changed 2 years ago by mgood

  • keywords needinfo added

Where are you trying to use a colon in InterWiki links that requires escaping?

I don't think that ":"s should be allowed in the InterWiki prefixes, since this will just lead to confusion. However, if there's another problem with the use of colons in InterWiki links please provide an explanation.

follow-up: ↓ 3   Changed 2 years ago by trac@…

It's for our general Wiki, which is based on MediaWiki. We just use Trac for individual projects. MediaWiki was our first Wiki engine; it has a lot of history, and it is not practical to move that stuff to Trac.

MediaWiki uses colons in some of the URLs. For instance, my user page would be at User:Dmahn, so I'd like to use an InterWiki link of the form: MyOtherWiki:User:Dmahn.

I have two other ideas about this:

  1. Just create a different InterWiki link for each type of link with a colon.
  2. Try to check the InterWiki output format while parsing the link, and if there aren't any parameters then don't bother splitting any arguments for it.

InterWiki needs special attention for the colons. Plain URLs with colons (e.g. http://digidescorp.com/wiki/User:Dmahn) don't cause problems.

in reply to: ↑ 2   Changed 2 years ago by cboos

  • keywords interwiki added; needinfo removed
  • owner changed from jonas to cboos
  • priority changed from normal to low
  • severity changed from normal to minor
  • milestone set to 0.10.1

Replying to trac@digidescorp.com:

a. Just create a different InterWiki link for each type of link with a colon.

Yes, why not something like:

User http://digidescorp.com/wiki/User: # User $1 in Main Wiki

...unless you have a great variety of such URLs.

Anyway, b. makes sense.

  Changed 2 years ago by trac@…

Yes I believe there are several:

  • Special:
  • User:
  • Category:

... And I'm not familiar enough with it to know if there are more. I think another option would be to create one kind of InterWiki link for this type of link, like:

MyWiki      http://digidescorp.com/wiki/
MyWikiTyped http://digidescorp.com/wiki/$1:$2

Then I can use MyWikiTyped:User:Dmahn.

This may be a way to keep down the number of links to remember/manage. However, after sleeping on it, I think option b. would ultimately be most intuitive:

        numargs = len( re.findall(InterWikiMap._argspec_re, url) )
        if numargs > 0:
            args = target.split(':', (numargs - 1))
        else:
            args = [target]

What do you think?

  Changed 2 years ago by trac@…

P.S. The code above for option b. seems to work like a charm!

  Changed 2 years ago by cboos

  • status changed from new to assigned

Yes, something like that ;) Thanks for the code snippet.

  Changed 2 years ago by trac@…

No problem!

However, I've reconsidered about breaking out the extra arguments (i.e. (numargs - 1)). That could work badly for duplicated or missing arguments, so probably should just do all or nothing -- split them all or none. Otherwise, would have to check the actual numbers of each argument and find the highest number.

I'm still a little perplexed about Python's callbacks. I mean, they don't seem to have any extra arguments to put pointers, etc. into. For instance ... the re.sub() function could be used to find the max argument number (not replacing the strings, but examining them), but the function doesn't take an extra argument that could be used to accumulate the max value.

I'm having an unrelated problem like that, where there is a callback for each line of data, but I just want to accumulate them all (for FTP). I can use a globals() thing, but I would hate to do that.

  Changed 2 years ago by trac@…

OK, so just for my own edification, I mean some better options might be ...

Either this (all or nothing):

        isargform = (len( re.findall(InterWikiMap._argspec_re, url) ) > 0)
        if isargform:
            args = target.split(':')
        else:
            args = [target]

Or this (which doesn't account for args intended to be omitted above the highest numbered):

        formalargs = re.findall(InterWikiMap._argspec_re, url)
        maxargnum = 0
        for a in formalargs:
            num = int(a[1:])
            if num > maxargnum:
                maxargnum = num
        if maxargnum > 0:
            args = target.split(':', (maxargnum - 1))
        else:
            args = [target]

  Changed 2 years ago by trac@…

Or ... here's a variant of the second one with more of the "one-liner" feel that Python seems to promote:

        maxargnum = max( [int(a[1:]) for a in re.findall(InterWikiMap._argspec_re, url)].append(0) )
        if maxargnum > 0:
            args = target.split(':', (maxargnum - 1))
        else:
            args = [target]

This second option is probably not as "correct" as the first one (all or nothing), but I see it maybe having more of the "do what I mean" ability.

  Changed 2 years ago by Dan <trac@…>

Sorry ... too greedy on that last one, as append() appears to return None.

        maxargnum = max( [0] + [int(a[1:]) for a in re.findall(InterWikiMap._argspec_re, url)] )
        if maxargnum > 0:
            args = target.split(':', (maxargnum - 1))
        else:
            args = [target]

  Changed 2 years ago by cboos

  • status changed from assigned to closed
  • resolution set to fixed
  • milestone changed from 0.10.1 to 0.10

Fixed in [3711]. As there were some other bugfixes to do for InterWiki, I took this occasion to integrate your code. Thanks!

Add/Change #3643 (InterWiki Link Colon Esacape)

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.