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 return true for e-mail #1674

Open
mjancarik opened this issue May 18, 2021 · 7 comments
Open

isURL return true for e-mail #1674

mjancarik opened this issue May 18, 2021 · 7 comments

Comments

@mjancarik
Copy link

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
Copy link
Contributor

I was going to submit a PR to fix this, but then I saw these tests...

it('should accept urls containing authentication information', () => {
test({
validator: 'isURL',
args: [{ disallow_auth: false }],
valid: [
'user@example.com',
'user:@example.com',
'user:password@example.com',
],
invalid: [
'user:user:password@example.com',
'@example.com',
':@example.com',
':example.com',
],
});
});

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

@mjancarik
Copy link
Author

Hi,

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

@raghavbk
Copy link

raghavbk commented Oct 3, 2021

@ezkemboi can i work on this issue

@ezkemboi
Copy link
Member

ezkemboi commented Oct 3, 2021

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

@Jassi10000-zz
Copy link

@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
Copy link

ffxsam commented Mar 12, 2023

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
Copy link

Yuniac commented May 9, 2024

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

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

No branches or pull requests

9 participants