diff options
author | diosmosis <benaka@piwik.pro> | 2015-09-10 02:18:33 +0300 |
---|---|---|
committer | diosmosis <benaka@piwik.pro> | 2015-09-10 02:18:33 +0300 |
commit | a23498b4fe55e8b34cc79c3dcb99a5a69b830106 (patch) | |
tree | 946be0189f27a1e2f3cdb6a405dee011ff96081f /plugins/SitesManager | |
parent | e8ed895332f6bd4c614fd6e9234eb59d4c2d060d (diff) |
Check for scheme in SitesManager/API instead of 'http' starting string + fix SitesManager/ApiTest.
Diffstat (limited to 'plugins/SitesManager')
-rw-r--r-- | plugins/SitesManager/API.php | 5 | ||||
-rw-r--r-- | plugins/SitesManager/tests/Integration/ApiTest.php | 8 |
2 files changed, 8 insertions, 5 deletions
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); |