Duplicate \XF\BbCode\ProcessorAction\AutoLink :: filterString produces invalid URL tags

DragonByte Tech

Well-known member
Affected version
2.1.0
This is not actually something I can't replicate here @ this site, but I can @ our site and also locally (locally I've tested it with all addons disabled).

I've modified \XF\BbCode\ProcessorAction\AutoLink, mostly inside public function filterString($string, array $options, Processor $processor), to give me an idea of the progress of the function:
Code:
String before autoLink: www.test.de?test=test
String after unfurlLinkRegex: [URL="http://www.test.de?test=test"]www.test.de?test=test[/URL]
Parameter passed to autoLinkUrl: www.test.de?test=test[/URL]
String after autoLinkRegex: [URL="http://www.test.de?test=test"][URL="http://www.test.de?test=test[/URL]"]www.test.de?test=test[/URL][/URL]


This is the current value of $autoLinkRegex in my copy of the files:
PHP:
$autoLinkRegex = '(?<=[^a-z0-9@/\.-]|^)(?<!\]\(|url=(?:"|\')|url\]|url\sunfurl=(?:"|\')true(?:"|\')\]|img\])(https?://|www\.)[^\s"<>{}`]+';


The issue can be confirmed on https://regex101.com:
197520

However, if I update the regex to this:
PHP:
$autoLinkRegex = '(?<=[^a-z0-9@/\.-]|^)(?<!\]\(|url=(?:"|\')|url\]|url\sunfurl=(?:"|\')true(?:"|\')\]|img\])(https?://|www\.)[^\s"<>{}`\[]+';
(Important part: \[ before the ]+ bit at the end)

The regex works on the website:
197521

Producing this output:
Code:
String before autoLink: www.test.de?test=test
String after unfurlLinkRegex: [URL="http://www.test.de?test=test"]www.test.de?test=test[/URL]
Parameter passed to autoLinkUrl: www.test.de?test=test
String after autoLinkRegex: [URL="http://www.test.de?test=test"][URL="http://www.test.de?test=test"]www.test.de?test=test[/URL][/URL]


Which still doesn't work when previewing it. At this point, further attempts at debugging branches off because I don't know what the intended functionality is;
  1. Is public function unfurlLinkUrl($url) correct, and it should add the surrounding URL tags?
    If so, the problem is likely that the $autoLinkRegex should probably include the URL tags in $match[0] so the auto linker isn't ran.
  2. Is public function unfurlLinkUrl($url) wrong?
    If so, the problem is likely that unfurlLinkUrl should not add URL tags, instead letting the autoLink function take care of this.
If you need any more information to assist in debugging this, please let me know.
 
This is not actually something I can't replicate here @ this site, but I can @ our site and also locally (locally I've tested it with all addons disabled).
Thanks for the detailed breakdown, but honestly I think this is somehow significant.

I think the crux of this is going to be figuring out why the behaviour is different.

Importantly, before we get into the code, can you confirm the exact contents of your editor (ideally with BB code mode toggled so you just get the plain text version) and then what you end up with afterwards in your xf_post table?

Essentially, before diving into what the code is doing, I need to be more clear about the specific steps you are following, and be more clear about the exact results you are seeing.

My steps so far are:

1. New message.
2. Paste www.test.de/?test=test
3. Submit

Results:
Code:
[URL='http://www.test.de/?test=test']www.test.de/?test=test[/URL]
 
1. New message.
2. Paste www.test.de/?test=test
3. Submit
Following these exact steps, the contents of the message column in xf_post is this:

Code:
[URL="http://www.test.de/?test=test"][URL="http://www.test.de/?test=test[/URL]"]www.test.de/?test=test[/URL][/URL]

If it's relevant; locally I'm using a Docker image of PHP 7.3.1, @ our site I'm using cPanel's PHP 7.3.2. I tested the issue using a Docker image of PHP 7.2 but there was no difference.
 
I was able to reproduce this on my development server following the steps above and it produces...

[URL='http://www.test.de/?test=test'][URL="http://www.test.de/?test=test[/URL]"]www.test.de/?test=test[/URL][/URL]

It does the same on my live site.

Ubuntu 18.04
PHP 7.2.15
 
Last edited:
I knew it rang a bell, and this is why, and this is why I can't repro it on any 2.1.1 forum. Just hadn't found the "evidence" that we'd fixed it :)
 
Top Bottom