From 35cc0a091e736fbd2211bfb2eac24ad4f056cba7 Mon Sep 17 00:00:00 2001 From: Ming Di Leom <2809763-curben@users.noreply.gitlab.com> Date: Sat, 5 Nov 2022 01:54:51 +0000 Subject: [PATCH] fix: skip invalid url --- src/script.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/script.js b/src/script.js index bfa439f..324f390 100644 --- a/src/script.js +++ b/src/script.js @@ -19,12 +19,22 @@ const f = async () => { const domains = new Set() for (const { url } of domainsArray) { - const parsedUrl = new URL(url.replace(/\*\./g, '').replace(/^\[/, '')) + let parsedUrl = new URL('http://example.com') + try { + parsedUrl = new URL(url.replace(/\*\./g, '')) + } catch { + continue + } const domain = parsedUrl.hostname.replace(/\\/g, '').replace(/^www\./, '') domains.add(domain) } for (const { url } of linksArray) { - const parsedUrl = new URL(url) + let parsedUrl = new URL('http://example.com') + try { + parsedUrl = new URL(url) + } catch { + continue + } const domain = parsedUrl.hostname.replace(/\\/g, '').replace(/^www\./, '') domains.add(domain) }