diff --git a/link.module b/link.module index f3e5a37..061b430 100644 --- a/link.module +++ b/link.module @@ -458,6 +458,19 @@ function _link_validate(&$item, $delta, $field, $entity, $instance, $langcode, & * The entity containing this link. */ function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) { + // As this function can be called multiple times and the item is changed by + // reference we need to ensure that there's always the original data to + // process otherwise processed data are processed again which might leads to + // unexpected results. + if (!isset($item['_link_sanitize_raw'])) { + // Store copy of original data to use in case of a second call. + $item['_link_sanitize_raw'] = $item; + } + else { + // Restore original data to process. + $item = $item['_link_sanitize_raw']; + } + // Don't try to process empty links. if (empty($item['url']) && empty($item['title'])) { return;