From dc071d009548b5af04823d0f1b11c5a24878dff1 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 30 May 2022 17:20:03 +0530 Subject: [PATCH] use URL API to identify remote hrefs --- customize.dist/pages/index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/customize.dist/pages/index.js b/customize.dist/pages/index.js index b7aabdd59..bddeca76b 100644 --- a/customize.dist/pages/index.js +++ b/customize.dist/pages/index.js @@ -90,12 +90,21 @@ define([ }); }); + var isLocalURL = url => { + try { + return new URL(url, window.location.href).origin === window.location.origin; + } catch (err) { + console.error(err); + return /^\//.test(url); + } + }; + var pageLink = function (ref, loc, text) { if (!ref) { return; } var attrs = { href: ref, }; - if (!/^\//.test(ref)) { + if (!isLocalURL(ref)) { attrs.target = '_blank'; attrs.rel = 'noopener noreferrer'; }