Skip to content

Commit ee3b024

Browse files
authored
Merge pull request #49 from ItzNotABug/48-fix-invalid-url-host
Fix `ERR_INVALID_URL`.
2 parents 8b7a793 + 56a2084 commit ee3b024

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ghosler",
33
"description": "Send newsletter emails to your members, using your own email credentials!",
4-
"version": "0.96",
4+
"version": "0.97",
55
"private": true,
66
"main": "app.js",
77
"type": "module",

utils/newsletter.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,18 @@ export default class Newsletter {
234234
let elementUrl = $(element).attr(tag);
235235
if (elementUrl === '#' || !elementUrl) return;
236236

237+
/** @type {string | null} */
238+
let urlHost = null;
239+
237240
elementUrl = he.decode(elementUrl);
238-
const urlHost = new URL(elementUrl).host;
239241

240-
if (!domainsToExclude.includes(urlHost) && !urlsToExclude.includes(elementUrl)) {
242+
try {
243+
urlHost = new URL(elementUrl).host;
244+
} catch (error) {
245+
logError(logTags.Newsletter, Error(`Invalid URL found: ${elementUrl}, ${error.stack}.`));
246+
}
247+
248+
if (urlHost && !domainsToExclude.includes(urlHost) && !urlsToExclude.includes(elementUrl)) {
241249
trackedLinks.add(elementUrl);
242250
$(element).attr(tag, `${pingUrl}${elementUrl}`);
243251
}

0 commit comments

Comments
 (0)