Commit 26a2ba35 authored by John Fiala's avatar John Fiala
Browse files

Issue #1179944 by jcfiala,mr.york: Added variable_get calls so that the list...

Issue #1179944 by jcfiala,mr.york: Added variable_get calls so that the list of TLD that pass validation can be set by admins.
parent ba31bb07
......@@ -1074,7 +1074,8 @@ function link_cleanup_url($url, $protocol = "http") {
$protocol_match = preg_match("/^([a-z0-9][a-z0-9\.\-_]*:\/\/)/i", $url);
if (empty($protocol_match)) {
// But should there be? Add an automatic http:// if it starts with a domain name.
$domain_match = preg_match('/^(([a-z0-9]([a-z0-9\-_]*\.)+)('. LINK_DOMAINS .'|[a-z]{2}))/i', $url);
$LINK_DOMAINS = _link_domains();
$domain_match = preg_match('/^(([a-z0-9]([a-z0-9\-_]*\.)+)('. $LINK_DOMAINS .'|[a-z]{2}))/i', $url);
if (!empty($domain_match)) {
$url = $protocol ."://". $url;
}
......@@ -1154,11 +1155,12 @@ function link_validate_url($text) {
"ß", // ß
)), ENT_QUOTES, 'UTF-8');
$allowed_protocols = variable_get('filter_allowed_protocols', array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'mailto', 'irc', 'ssh', 'sftp', 'webcal'));
$LINK_DOMAINS = _link_domains();
// Starting a parenthesis group with (?: means that it is grouped, but is not captured
$protocol = '((?:'. implode("|", $allowed_protocols) .'):\/\/)';
$authentication = "(?:(?:(?:[\w\.\-\+!$&'\(\)*\+,;=" . $LINK_ICHARS . "]|%[0-9a-f]{2})+(?::(?:[\w". $LINK_ICHARS ."\.\-\+%!$&'\(\)*\+,;=]|%[0-9a-f]{2})*)?)?@)";
$domain = '(?:(?:[a-z0-9' . $LINK_ICHARS_DOMAIN . ']([a-z0-9'. $LINK_ICHARS_DOMAIN . '\-_\[\]])*)(\.(([a-z0-9' . $LINK_ICHARS_DOMAIN . '\-_\[\]])+\.)*('. LINK_DOMAINS .'|[a-z]{2}))?)';
$domain = '(?:(?:[a-z0-9' . $LINK_ICHARS_DOMAIN . ']([a-z0-9'. $LINK_ICHARS_DOMAIN . '\-_\[\]])*)(\.(([a-z0-9' . $LINK_ICHARS_DOMAIN . '\-_\[\]])+\.)*('. $LINK_DOMAINS .'|[a-z]{2}))?)';
$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}))';
......@@ -1207,6 +1209,14 @@ function link_validate_url($text) {
return FALSE;
}
/**
* Returns the list of allowed domains, including domains added by admins via variable_set/$config.
*/
function _link_domains() {
$link_extra_domains = variable_get('link_extra_domains', array());
return empty($link_extra_domains) ? LINK_DOMAINS : LINK_DOMAINS . '|' . implode('|', $link_extra_domains);
}
/**
* Implements hook_migrate_field_alter().
*/
......
......@@ -481,6 +481,10 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
//$valid2 = valid_url($link, TRUE);
//$this->assertEqual(TRUE, $valid2, "Using valid_url() on $link.");
}
// Test if we can make a tld valid:
variable_set('link_extra_domains', array('frog'));
$valid = link_validate_url('http://www.example.frog');
$this->assertEqual(LINK_EXTERNAL, $valid, "Testing that http://www.example.frog is a valid external link if we've added 'frog' to the list of valid domains.");
}
function testInvalidExternalLinks() {
......@@ -490,6 +494,7 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
'http://4827.0.0.2/',
'//www.example.com/',
'http://www.testß.com/', // ß not allowed in domain names!
'http://www.example.frog/', // Bad TLD
//'http://www.-fudge.com/', // domains can't have sections starting with a dash.
);
foreach ($links as $link) {
......@@ -497,5 +502,4 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
$this->assertEqual(FALSE, $valid, 'Testing that '. $link .' is not a valid link.');
}
}
}
Supports Markdown
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