Skip to content

Commit

Permalink
Merge pull request #49 from ItzNotABug/48-fix-invalid-url-host
Browse files Browse the repository at this point in the history
Fix `ERR_INVALID_URL`.
  • Loading branch information
ItzNotABug authored Apr 4, 2024
2 parents 8b7a793 + 56a2084 commit ee3b024
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ghosler",
"description": "Send newsletter emails to your members, using your own email credentials!",
"version": "0.96",
"version": "0.97",
"private": true,
"main": "app.js",
"type": "module",
Expand Down
12 changes: 10 additions & 2 deletions utils/newsletter.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,18 @@ export default class Newsletter {
let elementUrl = $(element).attr(tag);
if (elementUrl === '#' || !elementUrl) return;

/** @type {string | null} */
let urlHost = null;

elementUrl = he.decode(elementUrl);
const urlHost = new URL(elementUrl).host;

if (!domainsToExclude.includes(urlHost) && !urlsToExclude.includes(elementUrl)) {
try {
urlHost = new URL(elementUrl).host;
} catch (error) {
logError(logTags.Newsletter, Error(`Invalid URL found: ${elementUrl}, ${error.stack}.`));
}

if (urlHost && !domainsToExclude.includes(urlHost) && !urlsToExclude.includes(elementUrl)) {
trackedLinks.add(elementUrl);
$(element).attr(tag, `${pingUrl}${elementUrl}`);
}
Expand Down

0 comments on commit ee3b024

Please sign in to comment.