Commit a7d2015d authored by frigids-PUCC's avatar frigids-PUCC Committed by Renato Goncalves de Araujo
Browse files

Issue #2889683 by Yago Elias, RenatoG: Protocol-less URLs should be cleaned for use

parent 4f099b52
......@@ -1311,6 +1311,8 @@ function link_cleanup_url($url, $protocol = 'http') {
* True if a valid link, FALSE otherwise.
*/
function link_validate_url($text, $langcode = NULL) {
$text = _link_clean_relative($text);
$text = link_cleanup_url($text);
$type = link_url_type($text);
......@@ -1339,6 +1341,31 @@ function link_validate_url($text, $langcode = NULL) {
return $flag;
}
/**
* Cleaner of relatives urls.
*
* @param string $url
* The url to clean up the relative protocol.
*/
function _link_clean_relative($url) {
$check = substr($url, 0, 2);
if (isset($_SERVER['HTTPS']) &&
($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) ||
isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
$_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
$protocol = 'https://';
}
else {
$protocol = 'http://';
}
if ($check == '//') {
$url = str_replace('//', $protocol, $url);
}
return $url;
}
/**
* Type check a URL.
*
......@@ -1438,7 +1465,6 @@ function link_url_type($text) {
$ipv4 = '(?:[0-9]{1,3}(\.[0-9]{1,3}){3})';
$ipv6 = '(?:[0-9a-fA-F]{1,4}(\:[0-9a-fA-F]{1,4}){7})';
$port = '(?::([0-9]{1,5}))';
// Pattern specific to external links.
$external_pattern = '/^' . $protocol . '?' . $authentication . '?(' . $domain . '|' . $ipv4 . '|' . $ipv6 . ' |localhost)' . $port . '?';
......
......@@ -491,7 +491,6 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
'http://www.ex ample.com/',
'http://25.0.0/', // bad ip!
'http://4827.0.0.2/',
'//www.example.com/',
'http://www.testß.com/', // ß not allowed in domain names!
'http://.www.foo.bar./', // Bad TLD.
//'http://www.-fudge.com/', // domains can't have sections starting with a dash.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment