1 filter.pages.inc _filter_format_editor_link_url_validate(&$element, &$form_state)

Element validation function.

Clean up a URL and see if it will pass validation. Instead of stripping dangerous protocols we flag them as invalid to make the user aware.

See also




core/modules/filter/filter.pages.inc, line 530
User page callbacks for the Filter module.


function _filter_format_editor_link_url_validate(&$element, &$form_state) {
  $value = trim($element['#value']);

  // Allow empty values, since this will not result in a link tag anyway.
  if ($value === '') {
    form_set_value($element, $value, $form_state);

  // Clean up the URL so it's more likely to pass validation.
  $value = _filter_cleanup_url($value);

  form_set_value($element, $value, $form_state);

  // Flag if it has any dangerous protocols.
  $stripped_url = backdrop_strip_dangerous_protocols($value);
  $dangerous_protocols = $stripped_url !== $value ? TRUE : FALSE;

  // If it has dangerous protocols the URL is invalid. Or if it isn't either
  // a valid relative nor a valid absolute path.
  if ($dangerous_protocols || (!valid_url($value, TRUE) && !valid_url($value, FALSE))) {
    form_error($element, t('The URL %url is not valid.', array('%url' => $value)));