From 728da7f154d54a8dbd1ab10a481e8fdab2a2811e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B6=E5=B0=8F=E7=99=BD?= Date: Wed, 4 Jan 2023 21:44:23 +0800 Subject: [PATCH] fix: author is not iterable (#11555) Co-authored-by: xianjiantao --- lib/middleware/template.js | 2 +- lib/v2/test/index.js | 6 ++++++ test/middleware/template.js | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) 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 () => {