diff options
author | Richard John <richard.john@gmail.com> | 2018-07-01 21:54:52 +0300 |
---|---|---|
committer | Stefan Giehl <stefan@piwik.org> | 2018-07-01 21:54:51 +0300 |
commit | e515c230a15be68e179a626c7f9ccfbab436e7cd (patch) | |
tree | 10c63d80ee44d42b937c76859a5b7cbcac71776e /plugins/Provider/functions.php | |
parent | ac07aa40497901c7f2a7a99166a88a1b72265d53 (diff) |
Fixes #13045 - only attempt to link provider if it's a valid hostname (#13120)
Diffstat (limited to 'plugins/Provider/functions.php')
-rw-r--r-- | plugins/Provider/functions.php | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/plugins/Provider/functions.php b/plugins/Provider/functions.php index 3e2c4a2da8..60cf4d83d6 100644 --- a/plugins/Provider/functions.php +++ b/plugins/Provider/functions.php @@ -11,6 +11,7 @@ namespace Piwik\Plugins\Provider; use Piwik\Common; use Piwik\DataTable; use Piwik\Piwik; +use Zend_Validate_Hostname as HostnameValidator; /** * Return hostname portion of a domain name @@ -40,12 +41,13 @@ function getHostnameUrl($in) if ($in == DataTable::LABEL_SUMMARY_ROW || empty($in) || strtolower($in) === 'ip') { return null; } - - // if the name looks like it can be used in a URL, use it in one, otherwise link to startpage - if (preg_match("/^[-a-zA-Z0-9_.]+$/", $in)) { - return "http://www." . $in . "/"; + + // if the name is a valid hostname, return a URL - otherwise link to startpage + $validator = new HostnameValidator; + if ($validator->isValid($in)) { + return "http://" . $in . "/"; } else { - return "https://startpage.com/do/search?q=" . urlencode($in); + return "https://startpage.com/do/search?q=" . urlencode(getPrettyProviderName($in)); } } |