From c28c9aa16fe1c22e96d17824af9c94746cb2c84b Mon Sep 17 00:00:00 2001 From: Miguel Savignano Date: Sat, 30 Oct 2021 11:12:26 +0200 Subject: [PATCH] feat(isUrl): urls with empty user (#1833) * allow urls with empty user * use array extract * reuse auth split --- src/lib/isURL.js | 6 +++++- test/validators.js | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib/isURL.js b/src/lib/isURL.js index 253b3098c..aa6222a90 100644 --- a/src/lib/isURL.js +++ b/src/lib/isURL.js @@ -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('@'); diff --git a/test/validators.js b/test/validators.js index c347b9b44..aa08f07c1 100644 --- a/test/validators.js +++ b/test/validators.js @@ -364,6 +364,7 @@ describe('Validators', () => { 'http://www.foobar.com/~foobar', 'http://user:pass@www.foobar.com/', 'http://user:@www.foobar.com/', + 'http://:pass@www.foobar.com/', 'http://user@www.foobar.com', 'http://127.0.0.1/', 'http://10.0.0.0/',