Skip to content

isURL return true for e-mail #1674

@mjancarik

Description

@mjancarik

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

Activity

brybrophy

brybrophy commented on May 24, 2021

@brybrophy
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

mjancarik commented on Jun 11, 2021

@mjancarik
Author

Hi,

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

raghavbk

raghavbk commented on Oct 3, 2021

@raghavbk

@ezkemboi can i work on this issue

ezkemboi

ezkemboi commented on Oct 3, 2021

@ezkemboi
Member

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

Jassi10000-zz

Jassi10000-zz commented on Oct 25, 2021

@Jassi10000-zz

@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

ffxsam commented on Mar 12, 2023

@ffxsam

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

Yuniac commented on May 9, 2024

@Yuniac

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
WikiRik

WikiRik commented on Mar 28, 2025

@WikiRik
Member

This is desired behaviour atm, see also #1753 (comment)
The option disallow_auth is provided for this usecase

ffxsam

ffxsam commented on Apr 9, 2025

@ffxsam

The maintainers are obviously free to do what they want, but anyone arguing that user@example.com is a URL is flat-out wrong. It's not something subjective that's up for debate. I can cite evidence:

https://datatracker.ietf.org/doc/html/rfc3986#section-1.1.3

A URI can be further classified as a locator, a name, or both. The term "Uniform Resource Locator" (URL) refers to the subset of URIs that, in addition to identifying a resource, provide a means of locating the resource by describing its primary access mechanism (e.g., its network "location").

URI/URL examples: https://datatracker.ietf.org/doc/html/rfc3986#section-1.1.2

The RFC spec says "Each URI begins with a scheme name" and provides another clear example:

   The following are two example URIs and their component parts:

         foo://example.com:8042/over/there?name=ferret#nose
         \_/   \______________/\_________/ \_________/ \__/
          |           |            |            |        |
       scheme     authority       path        query   fragment
          |   _____________________|__
         / \ /                        \
         urn:example:animal:ferret:nose

Sorry to be pedantic, but if we're going to quote someone who claims that user@example.com is a URL "per spec," I think it needs to be called out.

I'm open to being challenged if someone can provide authoritative sources.

reopened this on Apr 9, 2025
WikiRik

WikiRik commented on Apr 9, 2025

@WikiRik
Member

Thanks for the extensive response, I've reopened the issue so we can take another look at it

ffxsam

ffxsam commented on Apr 9, 2025

@ffxsam

@WikiRik I appreciate being open to it! If there's no room for pedantry in engineering, then it ain't engineering. 😝

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @profnandaa@tux-tn@mjancarik@ffxsam@WikiRik

      Issue actions

        isURL return true for e-mail · Issue #1674 · validatorjs/validator.js