Skip to main content
Topic: Brackets mistakenly becoming part of URL (Read 2832 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Brackets mistakenly becoming part of URL

Try to click the links by @TE here and you will get a 404, because the link parses the outer bracket.
FYI, not broken on SMF.

Related? http://www.elkarte.net/community/index.php?topic=2815.0
~ SimplePortal Support Team ~

Re: Brackets mistakenly becoming part of URL

Reply #1

Quote from: Flavio93Zena – Try to click the links by @TE here and you will get a 404, because the link parses the outer bracket.
FYI, not broken on SMF.

Related? http://www.elkarte.net/community/index.php?topic=2815.0
Yep, seems to be a bug.. (I fixed the other post).
Here's another example (http://https://www.polymer-project.org/1.0/)

The closing bracket seems to be the issue..
Thorsten "TE" Eurich
------------------------

Re: Brackets mistakenly becoming part of URL

Reply #2

We need to add some extra "smarts" to the autolinker ... the basic problem is that a ) is a valid url character (along with a few other odd things) ... so as far as the regex or filter-var is concerned that trailing ) is a valid part of the link.

What we need to do is see if there is a leading ( as well, in which case we can assume that it was entered as (link)  -or-  we could do a more basic check and if it ends in a ) simply cut it as the odds of a link ending in that character are slim (but valid).

Either of those fixes will be less prone to the issue, not fail proof, but much better.

Tracked here: https://github.com/elkarte/Elkarte/issues/2171
Last Edit: August 25, 2015, 07:56:20 am by Spuds

Re: Brackets mistakenly becoming part of URL

Reply #3

Well I've looked at this a bit and honestly there is no great solution, its a bit of the limitation of the regex.

I explored adding a look behind to catch the trailing ) (and others symmetric issues)  but aside from getting a bit ugly, I was concerned with having the look ahead and look behind for this, we could end up in a exhaustive recursion situation.

So the solutions as I see them are:
1) Don't allow url's with )'s in them.  This is not the worst things since the autolinker is a "goodie" .. it will miss valid links which is what the url bbc is for anyway.
2) Pull that regex out of the current preg_replace array and add it to a separate preg_replace_callback where we can see if it starts with a ( and if so trim any trailing one.  Something like
Code: [Select]
if (is_string($result = preg_replace_callback('~(?<=([\s>\.(;\'"])|^)((?:http|https)://[\w\-_%@:|]+(?:\.[\w\-_%]+)*(?::\d+)?(?:/[\p{L}\w\-_\~%\.@!,\?&;=#(){}+:\'\\\\]*)*[/\w\-_\~%@\?;=#}\\\\]?)~ui', create_function('$m', 'return $m[1] !== "(" ? "[url]$m[2][/url]" : "[url]" . rtrim("$m[2]", ")") . "[/url])";'), $data)));
$data = $result;
That covers the most used case and still allows links with )'s in them, even trailing ones

So 1) is easy and cheap, 2) is more correct for this instance but a tad more expensive (probably not in real use) in terms of processing.

Re: Brackets mistakenly becoming part of URL

Reply #4

And to be honest, I have no idea which one to pick either, I'd kindly pass on and ask more expert people such as TE (no tag, already commented), @emanuele @Joshua Dickerson @ant59 etc. Pretty sure you need to discuss on this one.
~ SimplePortal Support Team ~


Re: Brackets mistakenly becoming part of URL

Reply #6

Didn't see that, well, it's a bump for that then ;)
~ SimplePortal Support Team ~

Re: Brackets mistakenly becoming part of URL

Reply #7

I knew I posted about this: http://www.elkarte.net/community/index.php?topic=499.0 :P
Duplicate. xD
Bugs creator.
Features destroyer.
Template killer.

Re: Brackets mistakenly becoming part of URL

Reply #8

Wth 2 years D:
~ SimplePortal Support Team ~

Re: Brackets mistakenly becoming part of URL

Reply #9

Flavio the bugs are solved when there are the conditions.
Pointing out that a bug is 2 years older does nothing else than irritate me (and likely others as well), and in this period I'm not in the mood of being irritated on this forum as well. Thank you.
Bugs creator.
Features destroyer.
Template killer.

 

Re: Brackets mistakenly becoming part of URL

Reply #10

I didn't mean it that way, you should know me enough after 2500 messages or so. ;) If I have something wrong with something/somebody, you know that the guy is the first getting a PM about it.
~ SimplePortal Support Team ~