Page MenuHomePhabricator

External URL syntax cannot handle square brackets
Closed, ResolvedPublic

Description

Older PHP frameworks sometimes use square brackets to pass whole arrays as GET parameters. The external URL sytnax of MediaWiki cannot handle such links: for example,

[http://www.danishliterature.info/index.php?id=2092&no_cache=1&tx_lfforfatter_pi2[stage]=1&tx_lfforfatter_pi2[uid]=109&tx_lfforfatter_pi2[lang]=_eng Jørgen-Frantz Jacobsen]

should give

<a href="http://www.danishliterature.info/index.php?id=2092&no_cache=1&tx_lfforfatter_pi2[stage]=1&tx_lfforfatter_pi2[uid]=109&tx_lfforfatter_pi2[lang]=_eng">Jørgen-Frantz Jacobsen</a>

but the actual result is

<a href="http://www.danishliterature.info/index.php?id=2092&no_cache=1&tx_lfforfatter_pi2">[stage</a>=1&tx_lfforfatter_pi2[uid]=109&tx_lfforfatter_pi2[lang]=_eng Jørgen-Frantz Jacobsen]

Automatic URL have the same problem. Replacing [ and ] with %5B and %5D usually helps, but is technically incorrect because these are reserved characters and shouldn't be urlencoded (nor do most browsers urlencode them when you copy the URL from the address bar), and it depends on the whim of the url processor whether the urlencoded version will still point to the same resource.


Version: unspecified
Severity: normal

Details

Reference
bz19411

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 10:43 PM
bzimport added a project: MediaWiki-Parser.
bzimport set Reference to bz19411.
bzimport added a subscriber: Unknown Object (MLST).
  • This bug has been marked as a duplicate of bug 3695 ***

Reopening, this has got nothing to do with nested links, and it is also much more severe: I see no valid use for putting a wikilink inside a normal link, but you cannot avoid putting square brackets in the URL if that is the format the target website chose to use. (Well, you can, as detailed above, but it is not guaranteed to work, and even when it does, it is unintuitive and 99% of the users will never find out on their own.)

The naming may be different, but the issue remains the same: bad parsing of square brackets within external URL syntax.

Shall I rename 3695 to that then? Wikilinks inside external links is a "well don't do that then" issue, while this one is a serious usability problem.

I prefer the name of this bug, actually. I say dupe this to that, and rename that one to this summary.

This one (brackets in the URL part) might be also easier to fix (or at least hack around): you can take advantage of the fact that square brackets are always balanced in an url and never at the end. Also, I have never seen an example where they are nested. It might be possible to add something like (\[[-\w_+%]*\][-\w_+%?=]+)? to the end of the URL regex to handle such links and still not mess up [1]-style automatically numbered links.

  • This bug has been marked as a duplicate of bug 3695 ***