Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/UrlHelper.php4
-rw-r--r--tests/PHPUnit/Unit/UrlHelperTest.php12
2 files changed, 13 insertions, 3 deletions
diff --git a/core/UrlHelper.php b/core/UrlHelper.php
index b1dfa46d12..5efba99996 100644
--- a/core/UrlHelper.php
+++ b/core/UrlHelper.php
@@ -101,8 +101,8 @@ class UrlHelper
*/
public static function isLookLikeUrl($url)
{
- return preg_match('~^(ftp|news|http|https)?://(.*)$~D', $url, $matches) !== 0
- && strlen($matches[2]) > 0;
+ return preg_match('~^((ftp|news|http|https)?:)?//(.*)$~D', $url, $matches) !== 0
+ && strlen($matches[3]) > 0;
}
/**
diff --git a/tests/PHPUnit/Unit/UrlHelperTest.php b/tests/PHPUnit/Unit/UrlHelperTest.php
index 9a006c7a40..dc4a97047b 100644
--- a/tests/PHPUnit/Unit/UrlHelperTest.php
+++ b/tests/PHPUnit/Unit/UrlHelperTest.php
@@ -28,9 +28,17 @@ class Core_UrlHelperTest extends \PHPUnit_Framework_TestCase
array('news://www.pi-wik.org', true),
array('https://www.tëteâ.org', true),
array('http://汉语/漢語.cn', true), //chinese
+
+ // valid network-path reference RFC3986
+ array('//piwik.org', true),
+ array('//piwik/hello?world=test&test', true),
+ array('//piwik.org/hello?world=test&test', true),
+
// invalid urls
array('it doesnt look like url', false),
array('/index?page=test', false),
+ array('http:/index?page=test', false),
+ array('http/index?page=test', false),
array('test.html', false),
array('/\/\/\/\/\/\\\http://test.com////', false),
array('jmleslangues.php', false),
@@ -46,7 +54,7 @@ class Core_UrlHelperTest extends \PHPUnit_Framework_TestCase
*/
public function testIsUrl($url, $isValid)
{
- $this->assertEquals($isValid, UrlHelper::isLookLikeUrl($url));
+ $this->assertEquals($isValid, UrlHelper::isLookLikeUrl($url), "$url failed test");
}
/**
@@ -196,6 +204,8 @@ class Core_UrlHelperTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('', UrlHelper::getHostFromUrl(null));
$this->assertEquals('localhost', UrlHelper::getHostFromUrl('http://localhost'));
$this->assertEquals('localhost', UrlHelper::getHostFromUrl('http://localhost/path'));
+ $this->assertEquals('localhost', UrlHelper::getHostFromUrl('//localhost/path'));
+ $this->assertEquals('localhost', UrlHelper::getHostFromUrl('//localhost/path?test=test2'));
$this->assertEquals('localhost', UrlHelper::getHostFromUrl('localhost/path'));
$this->assertEquals('sub.localhost', UrlHelper::getHostFromUrl('sub.localhost/path'));
$this->assertEquals('sub.localhost', UrlHelper::getHostFromUrl('http://sub.localhost/path/?query=test'));