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

isURL() incorrectly claims http:// is valid url #642

Closed
src-code opened this issue Mar 23, 2017 · 5 comments
Closed

isURL() incorrectly claims http:// is valid url #642

src-code opened this issue Mar 23, 2017 · 5 comments
Labels

Comments

@src-code
Copy link

validator.isURL('http://', { require_host: false }); // returns true

I understand that I could set require_host: true to get the right result, but then if the test string is a relative url (/example/foo.html), it won't validate. And I can't just || two executions of isURL() to cover both cases (as suggested for a similar issue), because it will lead to an incorrect result because http:// is flagged as valid in the above example:

var str = '/example/foo.html';
validator.isURL(str, { require_host: true }) || validator.isURL(str, { require_host: false }) // true

var str = 'http://';
validator.isURL(str, { require_host: true }) || validator.isURL(str, { require_host: false }) // true

It seems like validator should recognize that passing a protocol and nothing else cannot be a valid url, even if configured for not requiring a hostname.

@chriso chriso added the 🐛 bug label Apr 5, 2017
@chriso chriso closed this as completed in fdea1d7 Jul 7, 2017
@chriso
Copy link
Collaborator

chriso commented Jul 7, 2017

This is fixed in an upcoming release.

@dsacramone
Copy link

Was this actually fixed, I am seeing this as a validURL, and I can't see how it is:

validator.isURL('http://www.te');

@src-code
Copy link
Author

src-code commented Sep 8, 2017 via email

@dsacramone
Copy link

validator.isURL('www.bro', { require_tld: true }) <-- WHY is this returning true. I clearly do NOT have a TLD here, yet, it is saying 'a-ok', why?

@chriso
Copy link
Collaborator

chriso commented Oct 27, 2017

@dsacramone see #623, #428, #429, #704 (comment).

www.bro is a syntactically-valid URL string, and bro is a syntactically-valid generic TLD. There is nothing special about the www subdomain, e.g. www.com is a valid hostname that resolves – there doesn't have to be anything between www and the TLD. Checking whether the generic TLD is registered with IANA is outside the scope of the library. The library doesn't, and will never, include the full, ever-changing list of generic TLDs – all it can do is check whether the string is valid. Checking whether the hostname resolves is also outside the scope of the library, although this is easy to do yourself if you're validating on the backend.

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

No branches or pull requests

3 participants