Skip to content

Commit

Permalink
feat(isUrl): urls with empty user (#1833)
Browse files Browse the repository at this point in the history
* allow urls with empty user

* use array extract

* reuse auth split
  • Loading branch information
MiguelSavignano authored and profnandaa committed Oct 31, 2021
1 parent c4df647 commit ecd94fe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib/isURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,17 @@ export default function isURL(url, options) {
if (options.disallow_auth) {
return false;
}
if (split[0] === '' || split[0].substr(0, 1) === ':') {
if (split[0] === '') {
return false;
}
auth = split.shift();
if (auth.indexOf(':') >= 0 && auth.split(':').length > 2) {
return false;
}
const [user, password] = auth.split(':');
if (user === '' && password === '') {
return false;
}
}
hostname = split.join('@');

Expand Down
1 change: 1 addition & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ describe('Validators', () => {
'http://www.foobar.com/~foobar',
'http://user:[email protected]/',
'http://user:@www.foobar.com/',
'http://:[email protected]/',
'http://[email protected]',
'http://127.0.0.1/',
'http://10.0.0.0/',
Expand Down

0 comments on commit ecd94fe

Please sign in to comment.