diff options
author | Matthieu Aubry <matt@piwik.org> | 2015-09-11 06:30:37 +0300 |
---|---|---|
committer | Matthieu Aubry <matt@piwik.org> | 2015-09-11 06:30:37 +0300 |
commit | 301dd813fb1e86beef8b3a11c89faa13dde9e649 (patch) | |
tree | 36199b8698b31f100edb938615cbec787059f0f8 | |
parent | 06c3acee1bfd2724b4905f35812b0c8a9ccbd915 (diff) | |
parent | d47806e2f21576b2ce40b90c697fe97a02f2779b (diff) |
Merge pull request #8744 from piwik/8722_correct_scheme_validation
Correctly parse all URL schemes in UrlHelper::isLookLikeUrl().
-rw-r--r-- | core/UrlHelper.php | 4 | ||||
-rw-r--r-- | plugins/SitesManager/API.php | 5 | ||||
-rw-r--r-- | plugins/SitesManager/tests/Integration/ApiTest.php | 8 | ||||
-rw-r--r-- | tests/PHPUnit/Unit/UrlHelperTest.php | 7 | ||||
-rw-r--r-- | tests/UI/specs/Installation_spec.js | 4 |
5 files changed, 19 insertions, 9 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/plugins/SitesManager/API.php b/plugins/SitesManager/API.php index fabdd616e6..65d2784592 100644 --- a/plugins/SitesManager/API.php +++ b/plugins/SitesManager/API.php @@ -1483,7 +1483,10 @@ class API extends \Piwik\Plugin\API foreach ($urls as &$url) { $url = $this->removeTrailingSlash($url); - if (strpos($url, 'http') !== 0) { + $scheme = parse_url($url, PHP_URL_SCHEME); + if (empty($scheme) + && strpos($url, '://') === false + ) { $url = 'http://' . $url; } $url = trim($url); diff --git a/plugins/SitesManager/tests/Integration/ApiTest.php b/plugins/SitesManager/tests/Integration/ApiTest.php index 76de4ba10f..3b26d215cb 100644 --- a/plugins/SitesManager/tests/Integration/ApiTest.php +++ b/plugins/SitesManager/tests/Integration/ApiTest.php @@ -59,8 +59,8 @@ class ApiTest extends IntegrationTestCase array(array()), // no urls array(array("")), array(""), - array("httpww://piwik.net"), - array("httpww://piwik.net/gqg~#"), + array("5http://piwik.net"), + array("???://piwik.net"), ); } @@ -161,8 +161,8 @@ class ApiTest extends IntegrationTestCase */ public function test_addSite_WithSeveralUrls_Succeeds_AndCreatesAliasUrls() { - $urls = array("http://piwik.net/", "http://piwik.com", "https://piwik.net/test/"); - $urlsOK = array("http://piwik.net", "http://piwik.com", "https://piwik.net/test"); + $urls = array("http://piwik.net/", "http://piwik.com", "https://piwik.net/test/", "piwik.net/another/test"); + $urlsOK = array("http://piwik.net", "http://piwik.com", "http://piwik.net/another/test", "https://piwik.net/test"); $idsite = API::getInstance()->addSite("super website", $urls); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $idsite); 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), ); } diff --git a/tests/UI/specs/Installation_spec.js b/tests/UI/specs/Installation_spec.js index 653852f3cc..6830091da6 100644 --- a/tests/UI/specs/Installation_spec.js +++ b/tests/UI/specs/Installation_spec.js @@ -112,8 +112,10 @@ describe("Installation", function () { it("should display the javascript tracking page when correct information is entered in the setup website page and next is clicked", function (done) { expect.screenshot("js_tracking").to.be.capture(function (page) { page.sendKeys('input[name=siteName]', 'Serenity'); - page.sendKeys('input[name=url]', 'serenity.com'); page.evaluate(function () { + // cannot use sendKeys since quickform does not use placeholder attribute + $('input[name=url]').val('serenity.com'); + $('select[name=timezone]').val('Europe/Paris'); $('select[name=ecommerce]').val('1'); }); |