Skip to content

Commit 0392208

Browse files
MiguelSavignanotheteladras
authored andcommitted
feat(isUrl): urls with empty user (validatorjs#1833)
* allow urls with empty user * use array extract * reuse auth split
1 parent 561d85e commit 0392208

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/lib/isURL.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,17 @@ export default function isURL(url, options) {
111111
if (options.disallow_auth) {
112112
return false;
113113
}
114-
if (split[0] === '' || split[0].substr(0, 1) === ':') {
114+
if (split[0] === '') {
115115
return false;
116116
}
117117
auth = split.shift();
118118
if (auth.indexOf(':') >= 0 && auth.split(':').length > 2) {
119119
return false;
120120
}
121+
const [user, password] = auth.split(':');
122+
if (user === '' && password === '') {
123+
return false;
124+
}
121125
}
122126
hostname = split.join('@');
123127

test/validators.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ describe('Validators', () => {
364364
'http://www.foobar.com/~foobar',
365365
'http://user:[email protected]/',
366366
'http://user:@www.foobar.com/',
367+
'http://:[email protected]/',
367368
368369
'http://127.0.0.1/',
369370
'http://10.0.0.0/',

0 commit comments

Comments
 (0)