From e1d91a591e035e746223f77ad74c7921fe204f7f Mon Sep 17 00:00:00 2001 From: Henry Wang Date: Thu, 21 Feb 2019 07:24:55 +0000 Subject: [PATCH] del: line breaker handling in middleware (#1592) * del: remove line breaker handling As it's slowing down RSSHub drastically * del: related test case * feat: weibo line breaker handling --- lib/middleware/template.js | 11 ----------- lib/routes/test/index.js | 8 -------- lib/routes/weibo/user2.js | 1 + test/middleware/template.js | 13 ------------- 4 files changed, 1 insertion(+), 32 deletions(-) diff --git a/lib/middleware/template.js b/lib/middleware/template.js index 3fcdedd12b..eeb6b3e4f6 100644 --- a/lib/middleware/template.js +++ b/lib/middleware/template.js @@ -48,17 +48,6 @@ module.exports = async (ctx, next) => { const itunes_duration = Math.floor(item.enclosure_length / 3600) + ':' + Math.floor((item.enclosure_length % 3600) / 60) + ':' + (((item.enclosure_length % 3600) % 60) / 100).toFixed(2).slice(-2); item.itunes_duration = itunes_duration; } - - if (item.description) { - item.description = item.description - .trim() - .replace(/(\r\n|\r|\n)/g, '
') - .replace(/^(
| |)+|(
| |)+$/g, ''); - } - - if (item.author) { - item.author = item.author.trim(); - } }); } diff --git a/lib/routes/test/index.js b/lib/routes/test/index.js index 79bac4a21e..cc112a5c26 100644 --- a/lib/routes/test/index.js +++ b/lib/routes/test/index.js @@ -23,14 +23,6 @@ module.exports = async (ctx) => { link: `https://github.com/DIYgod/RSSHub/issues/0`, author: `DIYgod0`, }); - } else if (ctx.params.id === 'linebreaker') { - item.push({ - title: `Long Title `, - description: `

\r\n\r\n Description \n\r with \r\n newlines \r\n\r\n

`, - pubDate: new Date(`2018-3-1`).toUTCString(), - link: `https://github.com/DIYgod/RSSHub/issues/0`, - author: `DIYgod0`, - }); } for (let i = 1; i < 6; i++) { diff --git a/lib/routes/weibo/user2.js b/lib/routes/weibo/user2.js index c8ea2af3a3..b31c284bb1 100644 --- a/lib/routes/weibo/user2.js +++ b/lib/routes/weibo/user2.js @@ -35,6 +35,7 @@ module.exports = async (ctx) => { wb.description = titleEle .html() .replace(/^\s+|\s+$/g, '') + .replace(/(\r\n|\r|\n)/g, '
') .replace(/thumbnail/, 'large'); wb.pubDate = date(item.find('.link_d').html(), 8); wb.link = item.find('.wgtCell_tm a').attr('href'); diff --git a/test/middleware/template.js b/test/middleware/template.js index 91db405de9..a07a9aa8d9 100644 --- a/test/middleware/template.js +++ b/test/middleware/template.js @@ -66,17 +66,4 @@ describe('template', () => { const parsed = await parser.parseString(response.text); expect(parsed.items[0].title.length).toBe(103); }); - - it(`replace newlines with
`, async () => { - const response = await request.get('/test/linebreaker'); - const parsed = await parser.parseString(response.text); - const test = parsed.items[0].content; - - // line breakers should have been replaced with
- expect(test).not.toContain('\r'); - expect(test).not.toContain('\n'); - - // content should not start with and/or end with
|
, which are meaningless - expect(test).toEqual(expect.not.stringMatching(/^(
| |)+|(
| |)+$/g)); - }); });