Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
Morbus IffWouldn'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.
Comment #2
(not verified) CreditAttribution: commentedI're right. So insted:
put code:
', ' ', $item['DESCRIPTION']);
$title = ereg_replace('/^(.*?)[^[:alnum:];&].*?$/', "\\1", truncate_utf8($title, 40)) . "...";
?>
Comment #3
(not verified) CreditAttribution: commentedOops.
Comment #4
magico CreditAttribution: magico commentedVerified.
Comment #5
StevenPatzComment #6
mustafau CreditAttribution: mustafau commentedComment #7
alex_b CreditAttribution: alex_b commentedMarking duplicate in favor of a more mature patch #404356: Aggregator should strip tags before using beginning of description tag as title.