fix: author is not iterable (#11555)

Co-authored-by: xianjiantao <xianjiantao@bytedance.com>
This commit is contained in:
零小白 2023-01-04 21:44:23 +08:00 committed by GitHub
parent e455abe486
commit 728da7f154
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 1 deletions

View File

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

View File

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

View File

@ -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 () => {