diff --git a/lib/middleware/parameter.js b/lib/middleware/parameter.js index 86f5fa85e..5bcfbe14f 100644 --- a/lib/middleware/parameter.js +++ b/lib/middleware/parameter.js @@ -8,6 +8,7 @@ const md = require('markdown-it')({ html: true, }); const htmlToText = require('html-to-text'); +const sanitizeHtml = require('sanitize-html'); let mercury_parser; @@ -353,7 +354,7 @@ module.exports = async (ctx, next) => { for (const item of ctx.state.data.item) { let text; if (item.description) { - text = item.description.replaceAll(/<\/?[^>]+(>|$)/g, ''); + text = sanitizeHtml(item.description, { allowedTags: [], allowedAttributes: {} }); } if (text?.length) { item.description = text.length > ctx.query.brief ? `
${text.substring(0, ctx.query.brief)}…
` : `${text}
`; diff --git a/lib/v2/test/index.js b/lib/v2/test/index.js index 18def475a..c79739db2 100644 --- a/lib/v2/test/index.js +++ b/lib/v2/test/index.js @@ -223,6 +223,17 @@ module.exports = async (ctx) => { break; + case 'brief': + item.push({ + title: '小可愛', + description: '宇宙無敵
宇宙無敵宇宙無敵宇宙無敵宇宙無敵宇宙無敵宇宙無敵宇宙無敵宇宙無敵宇宙無敵宇宙無敵宇宙無敵宇宙無敵宇宙無敵宇宙無敵宇宙無敵宇宙無敵宇宙無敵宇宙無敵宇宙無敵宇宙無敵宇宙無敵宇宙無敵宇宙無敵宇宙無敵宇宙無敵…
' + ); + }); +}); + describe('multi parameter', () => { it(`filter before limit`, async () => { const response = await request.get('/test/filter-limit?filterout_title=2&limit=2');