It's problem of aggregator.module in Drupal 4.5.x and 4.6 also. I have detected this problem when "aggregate" posts from LiveJournal.com which have blank titles and html in description at the same time.

In aggregator.module in aggregator_parse_feed() at line 501 (Drupal 4.5.2) there is such code:

    if ($item['TITLE']) {
      $title = $item['TITLE'];
    }
    else {
      $title = preg_replace('/^(.*)[^\w;&].*?$/', "\\1", truncate_utf8($item['DESCRIPTION'], 40));
    }

I suppose that it is incorrect preg_replace call as since:
1) it doesn't cut html tags
2) it may incorrectly work with national chars (i.e. \w): maybe ereg_replace is better solution?

For correct processing I changed this code to such:

    if ($item['TITLE']) {
      $title = $item['TITLE'];
    }
    else {
//      $title = preg_replace('/^(.*)[^\w;&].*?$/', "\\1", truncate_utf8($item['DESCRIPTION'], 40));
        $title = ereg_replace('<.*?(>|$)', '', truncate_utf8($item['DESCRIPTION'], 40));
        $title = ereg_replace('/^(.*?)[^[:alnum:];&].*?$/', "\\1", $title) . "...";
    }

Comments

Morbus Iff’s picture

Title: Aggregator module: incorrect process html in description when title is blank » Aggregator: Corrupted title based on item description with HTML

Wouldn't you want to remove the HTML from the description FIRST, and then get the first 40 characters from the remainder? The proposed code could still return no title, especially if the first 40 characters of the description are something like "[a href="http://www.disobey.com/"][strong]an example of an empty title based on a 40 character trunc before HTML removal[/strong][/a]". As for the i18n stuff, I know nothing about it, so someone else will have to address the change to ereg instead of preg.

Anonymous’s picture

I're right. So insted:

        $title = ereg_replace('<.*?(>|$)', '', truncate_utf8($item['DESCRIPTION'], 40));
        $title = ereg_replace('/^(.*?)[^[:alnum:];&].*?$/', "\\1", $title) . "...";

put code:

        $title = ereg_replace('<.*

', ' ', $item['DESCRIPTION']);
$title = ereg_replace('/^(.*?)[^[:alnum:];&].*?$/', "\\1", truncate_utf8($title, 40)) . "...";
?>

Anonymous’s picture

Oops.

        $title = ereg_replace('<.*?\>', ' ', $item['DESCRIPTION']);
        $title = ereg_replace('/^(.*?)[^[:alnum:];&].*?$/', "\\1", truncate_utf8($title, 40)) . "...";
magico’s picture

Verified.

StevenPatz’s picture

Version: » 6.x-dev
Status: Active » Postponed (maintainer needs more info)
mustafau’s picture

Version: 6.x-dev » 7.x-dev
Status: Postponed (maintainer needs more info) » Needs work
alex_b’s picture

Status: Needs work » Closed (duplicate)