diff --git a/lib/middleware/template.js b/lib/middleware/template.js index a229f7c6b..60393cc1c 100644 --- a/lib/middleware/template.js +++ b/lib/middleware/template.js @@ -66,7 +66,7 @@ module.exports = async (ctx, next) => { if (typeof item.author === 'string') { item.author = collapseWhitespace(item.author); - } else if (typeof item.author === 'object') { + } else if (typeof item.author === 'object' && item.author !== null) { for (const a of item.author) { a.name = collapseWhitespace(a.name); } diff --git a/lib/v2/test/index.js b/lib/v2/test/index.js index 9fd68ff2b..dfc8f832b 100644 --- a/lib/v2/test/index.js +++ b/lib/v2/test/index.js @@ -214,6 +214,12 @@ module.exports = async (ctx) => { enclosure_type: 'image/jpeg', enclosure_length: 3661, itunes_duration: 36610, + }, + { + title: 'Title4 author is null', + pubDate: new Date(`2019-3-1`).toUTCString(), + link: `https://github.com/DIYgod/RSSHub/pull/11555`, + author: null, } ); } diff --git a/test/middleware/template.js b/test/middleware/template.js index 6698791c4..c2a22fb1f 100644 --- a/test/middleware/template.js +++ b/test/middleware/template.js @@ -84,6 +84,7 @@ describe('template', () => { const parsed = await parser.parseString(response.text); expect(parsed.items[2].author).toBe(['DIYgod1', 'DIYgod2'].map((name) => name).join(', ')); expect(parsed.items[3].author).toBe(['DIYgod3', 'DIYgod4', 'DIYgod5'].map((name) => name).join(', ')); + expect(parsed.items[4].author).toBeUndefined(); }); it(`long title`, async () => {