If the link module is installed an enabled, it will allow the creation of a field type of "link" in a node. This field allows and correctly processes an entry of a plain domain name such as "example.com" by adding the protocol specifier and delimiter ("http://") to the beginning of the entered plain text. The link module performs a validation on the entered value at the time the node is saved or updated.

However, when linkchecker processes that field, it takes the entered value and makes it into an absolute internal URL of the form http://mysite.com/example.com, which will almost always fail to resolve as a valid link (assuming internal and external links are being checked). It is possible to work around this problem by entering a valid external URL in the field, but when users are entering data, this will often not happen.

The correct fix is for linkchecker to run the URL extracted from the link field through the function "link_cleanup_url()" in the link module. This function will always be present if there is a link_field in the node. This replicates the behaviour of the link module when it is checking the link itself.

The change is required in function linkchecker_parse_fields() in the linkchecker.module file.

      case 'link_field':
        foreach ($entity_field as $language) {
          foreach ($language as $item) {
            $options = drupal_parse_url(link_cleanup_url($item['url']));
            $title = !empty($item['title']) ? $item['title'] : '';
            $text_items[] = $text_items_by_field[$field['field_name']][] = l($title, $options['path'], $options);
            $text_items[] = $text_items_by_field[$field['field_name']][] = _linkchecker_check_markup($title, NULL, linkchecker_entity_language($entity_type, $entity), TRUE);
#1 linkchecker-handle_plain_link_fields-1948782-1.patch840 bytesjlscott
PASSED: [[SimpleTest]]: [MySQL] 159 pass(es). View
Members fund testing for the Drupal project. Drupal Association Learn more


jlscott’s picture

Status: Active » Needs review
840 bytes
PASSED: [[SimpleTest]]: [MySQL] 159 pass(es). View

Patch attached.

hass’s picture

Thanks a lot for sharing this. I asked for this in #1535594: Allow other modules to reuse the link building logics, but never received any feedback. Are you able to write a test for this, please?

hass’s picture

Title: Linkchecker does not handle plain link fields » Linkchecker does not handle link cleanup on 'link' fields
Status: Needs review » Fixed
hass’s picture

Version: 7.x-1.x-dev » 6.x-2.x-dev
Status: Fixed » Patch (to be ported)
jlscott’s picture

Sorry for the delay in responding. I am not familiar with writing tests for patches, so I will need to learn how. Any pointers will be appreciated.