From e8ed895332f6bd4c614fd6e9234eb59d4c2d060d Mon Sep 17 00:00:00 2001 From: diosmosis <benaka@piwik.pro> Date: Wed, 9 Sep 2015 14:30:44 -0700 Subject: [PATCH] Correctly parse URL schemes in UrlHelper::isLookLikeUrl(). --- core/UrlHelper.php | 4 ++-- tests/PHPUnit/Unit/UrlHelperTest.php | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core/UrlHelper.php b/core/UrlHelper.php index 3a550c8eb3..4a0ac0fa0a 100644 --- a/core/UrlHelper.php +++ b/core/UrlHelper.php @@ -107,8 +107,8 @@ class UrlHelper */ public static function isLookLikeUrl($url) { - return preg_match('~^((ftp|news|http|https)?:)?//(.*)$~D', $url, $matches) !== 0 - && strlen($matches[3]) > 0; + return preg_match('~^(([[:alpha:]][[:alnum:]+.-]*)?:)?//(.*)$~D', $url, $matches) !== 0 + && strlen($matches[3]) > 0; } /** diff --git a/tests/PHPUnit/Unit/UrlHelperTest.php b/tests/PHPUnit/Unit/UrlHelperTest.php index 49c33cc0df..e972d20d54 100644 --- a/tests/PHPUnit/Unit/UrlHelperTest.php +++ b/tests/PHPUnit/Unit/UrlHelperTest.php @@ -30,6 +30,11 @@ class UrlHelperTest extends \PHPUnit_Framework_TestCase array('https://www.tëteâ.org', true), array('http://汉è¯/漢語.cn', true), //chinese + array('rtp://whatever.com', true), + array('testhttp://test.com', true), + array('cylon://3.hmn', true), + array('://something.com', true), + // valid network-path reference RFC3986 array('//piwik.org', true), array('//piwik/hello?world=test&test', true), @@ -45,7 +50,7 @@ class UrlHelperTest extends \PHPUnit_Framework_TestCase array('jmleslangues.php', false), array('http://', false), array(' http://', false), - array('testhttp://test.com', false), + array('2fer://', false), ); } -- GitLab