fix: fuck some unstandard url (#2961)

This commit is contained in:
Cloud
2019-08-30 14:37:25 +08:00
committed by DIYgod
parent 5ef27461a0
commit 3c2200cd4b

View File

@@ -39,6 +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 && !baseUrl.match(/^https?:\/\//)) {
if (baseUrl.match(/^\/\//)) {
baseUrl = 'http:' + baseUrl;
@@ -54,7 +55,11 @@ module.exports = async (ctx, next) => {
// absolute link
if (baseUrl) {
$ele.attr('href', new URL($ele.attr('href'), baseUrl).href);
try {
$ele.attr('href', new URL($ele.attr('href'), baseUrl).href);
} catch (e) {
// no-empty
}
}
});
@@ -74,7 +79,11 @@ module.exports = async (ctx, next) => {
// absolute link
if (baseUrl) {
$ele.attr('src', new URL($ele.attr('src'), baseUrl).href);
try {
$ele.attr('src', new URL($ele.attr('src'), baseUrl).href);
} catch (e) {
// no-empty
}
}
// referrerpolicy