From 21572cd6afa065c32ff0a2ad5759935dbb2ad50d Mon Sep 17 00:00:00 2001 From: Matteo Pierro Date: Sat, 30 Oct 2021 08:59:19 +0300 Subject: [PATCH] fix(isUrl): allow url with column and no port (#1751) --- src/lib/isURL.js | 2 +- test/validators.js | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/lib/isURL.js b/src/lib/isURL.js index 7f6e0ba5f..253b3098c 100644 --- a/src/lib/isURL.js +++ b/src/lib/isURL.js @@ -136,7 +136,7 @@ export default function isURL(url, options) { } } - if (port_str !== null) { + if (port_str !== null && port_str.length > 0) { port = parseInt(port_str, 10); if (!/^[0-9]+$/.test(port_str) || port <= 0 || port > 65535) { return false; diff --git a/test/validators.js b/test/validators.js index 279796869..a5e975884 100644 --- a/test/validators.js +++ b/test/validators.js @@ -535,6 +535,31 @@ describe('Validators', () => { }); }); + it('should validate URLs with column and no port', () => { + test({ + validator: 'isURL', + valid: [ + 'http://example.com:', + 'ftp://example.com:', + ], + invalid: [ + 'https://example.com:abc', + ], + }); + }); + + it('should validate sftp protocol URL containing column and no port', () => { + test({ + validator: 'isURL', + args: [{ + protocols: ['sftp'], + }], + valid: [ + 'sftp://user:pass@terminal.aws.test.nl:/incoming/things.csv', + ], + }); + }); + it('should validate protocol relative URLs', () => { test({ validator: 'isURL',