From 4020c36c19e5d490c5c6dbb03add91a4c5a7bfd7 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Wed, 28 Aug 2019 16:14:50 +0800 Subject: [PATCH] fix: check null base url --- lib/middleware/parameter.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/middleware/parameter.js b/lib/middleware/parameter.js index 863e86286..878c8aad3 100644 --- a/lib/middleware/parameter.js +++ b/lib/middleware/parameter.js @@ -39,7 +39,7 @@ module.exports = async (ctx, next) => { if (item.description) { const $ = cheerio.load(item.description); let baseUrl = item.link || ctx.state.data.link; - if (!baseUrl.match(/^https?:\/\//)) { + if (baseUrl && !baseUrl.match(/^https?:\/\//)) { if (baseUrl.match(/^\/\//)) { baseUrl = 'http:' + baseUrl; } else { @@ -53,7 +53,7 @@ module.exports = async (ctx, next) => { const $ele = $(ele); // absolute link - if (ctx.state.data.link) { + if (baseUrl) { $ele.attr('href', new URL($ele.attr('href'), baseUrl).href); } }); @@ -73,7 +73,7 @@ module.exports = async (ctx, next) => { } // absolute link - if (ctx.state.data.link) { + if (baseUrl) { $ele.attr('src', new URL($ele.attr('src'), baseUrl).href); }