Closed (duplicate)
Project:
Drupal core
Version:
7.x-dev
Component:
aggregator.module
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
28 Mar 2005 at 04:59 UTC
Updated:
26 Mar 2009 at 04:02 UTC
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) commentedI're right. So insted:
put code:
', ' ', $item['DESCRIPTION']);
$title = ereg_replace('/^(.*?)[^[:alnum:];&].*?$/', "\\1", truncate_utf8($title, 40)) . "...";
?>
Comment #3
(not verified) commentedOops.
Comment #4
magico commentedVerified.
Comment #5
stevenpatzComment #6
mustafau commentedComment #7
alex_b commentedMarking duplicate in favor of a more mature patch #404356: Aggregator should strip tags before using beginning of description tag as title.