0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

🐛 Fixed internal error for RSS feed when a post has no content

no issue

- initial report https://forum.ghost.org/t/rss-feed-stopped-working/9874
- `htmlRelativeToAbsolute` will return `null` if `null` is passed into it but `cheerio.load(null)` will throw a "Cannot read property 'parent' of null" error so we need to ensure we at least load an empty string
This commit is contained in:
Kevin Ansfield 2019-10-30 17:46:17 +00:00
parent cfb66ac161
commit 2dc6f30f11
2 changed files with 19 additions and 2 deletions

View file

@ -23,7 +23,7 @@ generateTags = function generateTags(data) {
generateItem = function generateItem(post, secure) {
const itemUrl = urlService.getUrlByResourceId(post.id, {secure, absolute: true});
const htmlContent = cheerio.load(urlUtils.htmlRelativeToAbsolute(post.html, itemUrl, {secure}), {decodeEntities: false});
const htmlContent = cheerio.load(urlUtils.htmlRelativeToAbsolute(post.html, itemUrl, {secure}) || '', {decodeEntities: false});
const item = {
title: post.title,
// @TODO: DRY this up with data/meta/index & other excerpt code

View file

@ -142,7 +142,7 @@ describe('RSS: Generate Feed', function () {
}).catch(done);
});
it('should no error if author is somehow not present', function (done) {
it('should not error if author is somehow not present', function (done) {
data.posts = [_.omit(posts[2], 'primary_author')];
generateFeed(baseUrl, data).then(function (xmlData) {
@ -160,6 +160,23 @@ describe('RSS: Generate Feed', function () {
}).catch(done);
});
it('should not error if post content is null', function (done) {
data.posts = [Object.assign({}, posts[2], {html: null})];
generateFeed(baseUrl, data).then(function (xmlData) {
should.exist(xmlData);
// special/optional tags
xmlData.should.match(/<title><!\[CDATA\[Short and Sweet\]\]>/);
xmlData.should.match(/<description><!\[CDATA\[test stuff/);
xmlData.should.match(/<content:encoded\/>/);
xmlData.should.match(/<media:content url="http:\/\/placekitten.com\/500\/200" medium="image"\/>/);
xmlData.should.match(/<dc:creator>/);
done();
}).catch(done);
});
it('should use meta_description and image where available', function (done) {
data.posts = [posts[2]];