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',