Issue #3373222 by Gábor Hojtsy, mcdruid: Fallback to feed item description does not strip HTML, only takes 40 chars even though field allows 255
parent
605b36bde2
commit
96a9946c34
|
@ -98,14 +98,14 @@ function aggregator_parse_feed(&$data, $feed) {
|
|||
$item[$key] = trim($value);
|
||||
}
|
||||
|
||||
// Resolve the item's title. If no title is found, we use up to 40
|
||||
// characters of the description ending at a word boundary, but not
|
||||
// splitting potential entities.
|
||||
// Resolve the item's title. If no title is found, we use up to 255
|
||||
// characters of the description ending at a word boundary.
|
||||
if (!empty($item['title'])) {
|
||||
$item['title'] = $item['title'];
|
||||
}
|
||||
elseif (!empty($item['description'])) {
|
||||
$item['title'] = preg_replace('/^(.*)[^\w;&].*?$/', "\\1", truncate_utf8($item['description'], 40));
|
||||
$clean_description = strip_tags(html_entity_decode($item['description'], ENT_QUOTES, 'UTF-8'));
|
||||
$item['title'] = truncate_utf8($clean_description, 255, TRUE, TRUE);
|
||||
}
|
||||
else {
|
||||
$item['title'] = '';
|
||||
|
|
|
@ -292,6 +292,10 @@ EOF;
|
|||
return $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'aggregator') . '/tests/aggregator_test_title_entities.xml';
|
||||
}
|
||||
|
||||
function getNoTitleSample() {
|
||||
return $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'aggregator') . '/tests/aggregator_test_title_from_desc.xml';
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates sample article nodes.
|
||||
*
|
||||
|
@ -1067,4 +1071,16 @@ class FeedParserTestCase extends AggregatorTestCase {
|
|||
$this->assertResponse(200, format_string('Feed %name exists.', array('%name' => $feed->title)));
|
||||
$this->assertRaw("Quote" Amp&");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a feed with no title; the description should be used to generate one.
|
||||
*/
|
||||
function testNoTitleSample() {
|
||||
$feed = $this->createFeed($this->getNoTitleSample());
|
||||
aggregator_refresh($feed);
|
||||
$this->drupalGet('aggregator/sources/' . $feed->fid);
|
||||
$this->assertResponse(200, format_string('Feed %name exists.', array('%name' => $feed->title)));
|
||||
$this->assertRaw("This description should be used to generate a title. This description should be used to generate a title. This description should be used to generate a title. This description should be used to generate a title. This description should be used to...");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<rss version="0.91">
|
||||
<channel>
|
||||
<title>Example with no title</title>
|
||||
<link>http://example.com</link>
|
||||
<description>Example RSS Feed With no Title so that a Title is parsed from the Description</description>
|
||||
<language>en-us</language>
|
||||
<item>
|
||||
<title></title>
|
||||
<link>http://example.com/example-turns-one</link>
|
||||
<description>This description should be used to generate a <title>title</title>. This description should be used to generate a title. This description should be used to generate a <title>title</title>. This description should be used to generate a title. This description should be used to generate a <title>title</title>. This description should be used to generate a title. This description should be used to generate a <title>title</title>. This description should be used to generate a title. This description should be used to generate a <title>title</title>. This description should be used to generate a title.</description>
|
||||
</item>
|
||||
</channel>
|
||||
</rss>
|
Loading…
Reference in New Issue