validatorjs / validator.js

String validation
MIT License
22.94k stars 2.28k forks source link

isURL return true for e-mail #1674

Open mjancarik opened 3 years ago

mjancarik commented 3 years ago

Describe the bug Hi,

What is the correct behaviour for isURL function when I give e-mail address? I would expect that return false.

Examples An example from the Node REPL:

Welcome to Node.js v14.16.0.
Type ".help" for more information.
> var validator = require('validator');
undefined
> validator.isURL('user@example.com');
true
> 

Additional context Validator.js version: 13.6.0 Node.js version: 14.16.0 OS platform: macOS

brybrophy commented 3 years ago

I was going to submit a PR to fix this, but then I saw these tests... https://github.com/validatorjs/validator.js/blob/907bb07b8d6be7d159791645960eb5f5017a99b6/test/validators.js#L672-L688

It seems that you can set the disallow_auth option to true and it will fail validation on an email.

mjancarik commented 3 years ago

Hi,

Thank you. I will try it. I would expect default behaviour with disallow_auth to true.

raghavbk commented 2 years ago

@ezkemboi can i work on this issue

ezkemboi commented 2 years ago

@raghavbk if you have a PR, please do it and we will review it. Thanks.

Jassi10000-zz commented 2 years ago

@mjancarik Buddy can you tell one thing

user@example.com : This will treated as an email due to the presence of " @ " in it , so I think its bound to return true to this

ffxsam commented 1 year ago

In no way is an email address a URL, as someone claimed in an issue.

mailto:xyz@xyz.net is a URL/URI, but xyz@xyz.net is not. This should be considered a bug.

Yuniac commented 3 months ago

Well, till someone figure out which way is the correct way, doing this works for everyone else:

validator.isURL('xyz@xyz.net', { disallow_auth: true }); // false