fix linkify to work with with ip addresses (#8226)

* fix linkify to work with with ip addresses

* update tests
This commit is contained in:
Tony Murray
2018-02-07 20:48:18 -06:00
committed by GitHub
parent 8abe508cfd
commit 6bbe5038e8
2 changed files with 3 additions and 3 deletions

View File

@ -185,7 +185,7 @@ function toner2colour($descr, $percent)
*/ */
function linkify($text) function linkify($text)
{ {
$regex = "/(http|https|ftp|ftps):\/\/[a-z0-9\-.]+\.[a-z]{2,5}(\/\S*)?/i"; $regex = "#(http|https|ftp|ftps)://[a-z0-9\-.]*[a-z0-9\-]+(/\S*)?#i";
return preg_replace($regex, '<a href="$0">$0</a>', $text); return preg_replace($regex, '<a href="$0">$0</a>', $text);
} }

View File

@ -55,13 +55,13 @@ class FunctionsTest extends TestCase
{ {
$input = 'foo@demo.net bar.ba@test.co.uk $input = 'foo@demo.net bar.ba@test.co.uk
www.demo.com http://foo.co.uk/ www.demo.com http://foo.co.uk/
sdfsd sdfsd ftp://192.168.1.1/help/me/now.php
http://regexr.com/foo.html?q=bar http://regexr.com/foo.html?q=bar
https://mediatemple.net.'; https://mediatemple.net.';
$expected = 'foo@demo.net bar.ba@test.co.uk $expected = 'foo@demo.net bar.ba@test.co.uk
www.demo.com <a href="http://foo.co.uk/">http://foo.co.uk/</a> www.demo.com <a href="http://foo.co.uk/">http://foo.co.uk/</a>
sdfsd sdfsd <a href="ftp://192.168.1.1/help/me/now.php">ftp://192.168.1.1/help/me/now.php</a>
<a href="http://regexr.com/foo.html?q=bar">http://regexr.com/foo.html?q=bar</a> <a href="http://regexr.com/foo.html?q=bar">http://regexr.com/foo.html?q=bar</a>
<a href="https://mediatemple.net">https://mediatemple.net</a>.'; <a href="https://mediatemple.net">https://mediatemple.net</a>.';