mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
fix linkify to work with with ip addresses (#8226)
* fix linkify to work with with ip addresses * update tests
This commit is contained in:
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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>.';
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user