Repository: validatorjs/validator.js
Pull request #1425 (2020-08-28 23:12:14)

fix(isUrl): add proper validation for emails
See: https://github.com/validatorjs/validator.js/issues/1375

## Checklist

- [ ] PR contains only changes related; no stray files, etc.
- [ ] README updated (where applicable)
- [ ] Tests written (where applicable)


codecov[bot]: # [Codecov](https://codecov.io/gh/validatorjs/validator.js/pull/1425?src=pr&el=h1) Report
> Merging [#1425](https://codecov.io/gh/validatorjs/validator.js/pull/1425?src=pr&el=desc) into [master](https://codecov.io/gh/validatorjs/validator.js/commit/2ec9426a3ce456665ac0ea79a91f9ea867122987?el=desc) will **not change** coverage.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/validatorjs/validator.js/pull/1425/graphs/tree.svg?width=650&height=150&src=pr&token=YzR3kbN1m2)](https://codecov.io/gh/validatorjs/validator.js/pull/1425?src=pr&el=tree)

```diff
@@            Coverage Diff            @@
##            master     #1425   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           95        95           
  Lines         1254      1254           
=========================================
  Hits          1254      1254           
```


| [Impacted Files](https://codecov.io/gh/validatorjs/validator.js/pull/1425?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/lib/isURL.js](https://codecov.io/gh/validatorjs/validator.js/pull/1425/diff?src=pr&el=tree#diff-c3JjL2xpYi9pc1VSTC5qcw==) | `100.00% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/validatorjs/validator.js/pull/1425?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/validatorjs/validator.js/pull/1425?src=pr&el=footer). Last update [2ec9426...7a0c524](https://codecov.io/gh/validatorjs/validator.js/pull/1425?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/src/lib/isURL.js b/src/lib/isURL.js
index 6ca916f..a509b16 100644
--- a/src/lib/isURL.js
+++ b/src/lib/isURL.js
@@ -100,7 +100,7 @@ export default function isURL(url, options) {
       return false;
     }
     auth = split.shift();
-    if (auth.indexOf(':') >= 0 && auth.split(':').length > 2) {
+    if (auth.indexOf(':') === -1 || (auth.indexOf(':') >= 0 && auth.split(':').length > 2)) {
       return false;
     }
   }


Test patch:
diff --git a/test/validators.js b/test/validators.js
index bac061f..1587fc8 100644
--- a/test/validators.js
+++ b/test/validators.js
@@ -339,6 +339,7 @@ describe('Validators', () => {
         'http://[::FFFF:129.144.52.38]:80/index.html',
         'http://[2010:836B:4179::836B:4179]',
         'http://example.com/example.json#/foo/bar',
+        'http://user:@www.foobar.com',
       ],
       invalid: [
         'http://localhost:3000/',
@@ -379,6 +380,7 @@ describe('Validators', () => {
         '////foobar.com',
         'http:////foobar.com',
         'https://example.com/foo/<script>alert(\'XSS\')</script>/',
+        'myemail@mail.com',
       ],
     });
   });