Validator.js: isURL method always returns false

Created on 9 Sep 2020  路  3Comments  路  Source: validatorjs/validator.js

Describe the bug
A clear and concise description of what the bug is.

The isURL method always returns false, regardless what the input string is. Also ignores the config object.

Examples

function checkIfUrlIsValid(url) {
   isURL(url)
}
checkIfUrlIsValid('www.index.hu') --> false
checkIfUrlIsValid('index.hu') --> false
checkIfUrlIsValid('https://www.index.hu') --> false
checkIfUrlIsValid('google.com') --> false

Additional context
Validator.js version: 13.1.1
Node.js version: node/12.8.1
OS platform: macOS

help wanted 馃悰 bug 馃攳needs-investigation

Most helpful comment

It should not, google.com, index.hu and www.index.hu are all domain's names not URIs based on RFC-3986.

I was facing the same issues with your module and valid-url so I decided to build a module as reliable as possible strictly based on RFC-3986: https://github.com/adrienv1520/node-uri

You can:

  • parse any URI (URNs, URLs, URIs with IDNs support, etc.);
  • get the safe Punycode ASCII or Unicode serialization of a domain;
  • check an URI, HTTP/HTTPS/Sitemap URL, IP, domain is valid with clear checking errors;
  • encode/decode an URI, HTTP/HTTPS/Sitemap URL.

I hope it could help.

All 3 comments

@zilahir, I tried this on MacOS, node/12.8.1 and validator.js 13.1.1 but it works fine.

var validator = require('validator') 

function checkIfUrlIsValid(url) {
    return validator.isURL(url)
}

console.log(checkIfUrlIsValid('www.index.hu')) // true 
console.log(checkIfUrlIsValid('index.hu')) // true
console.log(checkIfUrlIsValid('https://www.index.hu')) // true
console.log(checkIfUrlIsValid('google.com')) // true

I will need to do more investigations.

@ezkemboi hmmm interesting. i will create a demo project soon! thanks for the reply.

It should not, google.com, index.hu and www.index.hu are all domain's names not URIs based on RFC-3986.

I was facing the same issues with your module and valid-url so I decided to build a module as reliable as possible strictly based on RFC-3986: https://github.com/adrienv1520/node-uri

You can:

  • parse any URI (URNs, URLs, URIs with IDNs support, etc.);
  • get the safe Punycode ASCII or Unicode serialization of a domain;
  • check an URI, HTTP/HTTPS/Sitemap URL, IP, domain is valid with clear checking errors;
  • encode/decode an URI, HTTP/HTTPS/Sitemap URL.

I hope it could help.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

IOAyman picture IOAyman  路  4Comments

AnandChowdhary picture AnandChowdhary  路  3Comments

rubiin picture rubiin  路  3Comments

mum-never-proud picture mum-never-proud  路  4Comments

Maxreglez picture Maxreglez  路  3Comments