fix: check null base url

This commit is contained in:
DIYgod 2019-08-28 16:14:50 +08:00
parent b2355436cc
commit 4020c36c19
No known key found for this signature in database
GPG Key ID: EC0B76A252D3EF67
1 changed files with 3 additions and 3 deletions

View File

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