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

merge-requests/4835/head
Juraj Nemec 2023-09-15 18:55:55 +02:00
parent 605b36bde2
commit 96a9946c34
No known key found for this signature in database
GPG Key ID: 01EC3E1EECB5B2CA
3 changed files with 34 additions and 4 deletions

View File

@ -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'] = '';

View File

@ -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...");
}
}

View File

@ -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 &lt;title&gt;title&lt;/title&gt;. This description should be used to generate a title. This description should be used to generate a &lt;title&gt;title&lt;/title&gt;. This description should be used to generate a title. This description should be used to generate a &lt;title&gt;title&lt;/title&gt;. This description should be used to generate a title. This description should be used to generate a &lt;title&gt;title&lt;/title&gt;. This description should be used to generate a title. This description should be used to generate a &lt;title&gt;title&lt;/title&gt;. This description should be used to generate a title.</description>
</item>
</channel>
</rss>