Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix URL check #239

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Fix URL check #239

wants to merge 1 commit into from

Conversation

Jwiggiff
Copy link

This pull request changes the URL check for http downloads. Rather than using the previous REGEX, it uses the URL constructor built in to JavaScript. The previous REGEX had some weaknesses, including any URLs that contained square brackets (and probably some other characters as well). The new method uses the URL constructor in JavaScript. Rather than checking with a REGEX, it attempts to construct a new URL object using the provided URL string within a try/catch statement. This will throw an error on a malformed URL, which then returns false. This process is illustrated below.

try {
  new URL(URLString);
  return true; // Is a valid url since it was able to construct a URL object
} catch (_) {
  return false; // Invalid url since an error was thrown when constructing the object
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant