1 filter.pages.inc | _filter_cleanup_url($url) |
Clean up the URL for validation.
Attempts to create a URL that will pass validation: add a protocol if it looks like a domain but the protocol is missing; or create a valid, encoded internal alias.
Parameters
string $url: A URL before it is cleaned-up.
Return value
string: A cleaned-up URL that is either a properly formatted external URL or an internal path.
See also
_filter_format_editor_link_url_validate()
File
- core/
modules/ filter/ filter.pages.inc, line 583 - User page callbacks for the Filter module.
Code
function _filter_cleanup_url($url) {
// Will add a default protocol if missing on an external url.
$url = _filter_create_valid_external_url($url);
// If it's an external URL with a protocol we can skip the rest of the
// clean up.
if (_filter_url_has_protocol($url)) {
return $url;
}
// Return anchors as is.
if (substr($url, 0, 1) == '#') {
return $url;
}
// Return if it begins with a slash. Avoids issues such as:
// - extra language prefixes if it's a multilingual site;
// - adding extra prefixes if being re-edited;
// - a url getting double-encoded;
// - or domains with relative protocols.
// E.g. /fr/node/1, //domain.tld.
if (substr($url, 0, 1) == '/') {
return $url;
}
// Break up the components so we can build up an aliased internal path.
$url_parts = backdrop_parse_url($url);
return url($url_parts['path'], $url_parts);
}