Page MenuHomePhabricator

Link-Parsing fails if URL ends in ) when using "[name](link)" syntax
Closed, WontfixPublic

Description

When a URL of a link ends in ) the Markdown parser fails to properly render it.

e.g. when trying to use the URL https://en.wikipedia.org/wiki/Starship_Troopers_(film) in a [Foo](Bar) style Markdown link, the resulting link will miss the closing ) and the 2nd ) which should actually end the Markdown element will be rendered after the link.

Example: Bug Killer

Event Timeline

eliaspro created this task.Mar 2 2017, 10:48 PM

Workaround is to URL-encode the parenthesis (%29) or use the remarkup style

[Back to the Future](https://en.wikipedia.org/wiki/Starship_Troopers_(film%29)
[[ https://en.wikipedia.org/wiki/Starship_Troopers_(film) | Jurassic Park ]]

Results in:
[Back to the Future](https://en.wikipedia.org/wiki/Starship_Troopers_(film%29)
Jurassic Park

avivey renamed this task from Link-Parsing fails if URL ends in ) to Link-Parsing fails if URL ends in ) when using "[name](link)" syntax.Mar 3 2017, 10:21 PM
avivey added a project: Remarkup.
chad moved this task from Backlog to Parser on the Remarkup board.Mar 27 2017, 3:49 PM

The intent isn't unambiguous in the general case, consider: Blah blah (see also [x](y)).

The CommonMark spec describes balancing rules:

GitHub seems to implement something similar. For example, it does not render See the page at [Open Parenthesis](wiki/open_parenthesis() for more details as a link.

Organically, I think this rule is actually "Wikipedia is the only site on the internet which uses parentheses in URLs, and parsers should implement behavior which gets most Wikipedia pages right."

I think we have to balance the parentheses as we parse the string to get the right result? Maybe I can fake it with very clever regular expressions.

GitHub behaves oddly on these inputs:

[x](x()   Not a link.
[x](x(y)  Not a link
[x](x( )  Link to `x(`? Huh?

D19111 doesn't fix this in the general case, but should produce the desired behavior for most inputs such that the input is in the form [x](y) and y is the URI of a Wikipedia article.

Notably, it does not make [x](y((()))) behave in a way that is similar to GitHub or CommonMark.

epriestley closed this task as Wontfix.Apr 4 2018, 1:59 PM
epriestley claimed this task.

I don't currently plan to change the remaining edge case behaviors since I'm not sure they ever occur in the wild.