Skip to content

Commit 5d2ff83

Browse files
committed
do not check if the host is valid if no host is specified
1 parent 37cbd5c commit 5d2ff83

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/lib/isURL.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ export default function isURL(url, options) {
152152
if (options.host_whitelist) {
153153
return checkHost(host, options.host_whitelist);
154154
}
155+
156+
if (host === '' && !options.require_host) {
157+
return true;
158+
}
159+
155160
if (!isIP(host) && !isFQDN(host, options) && (!ipv6 || !isIP(ipv6, 6))) {
156161
return false;
157162
}

test/validators.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,24 @@ describe('Validators', () => {
472472
});
473473
});
474474

475+
it('should validate postgres URLs without a host', () => {
476+
test({
477+
validator: 'isURL',
478+
args: [{
479+
protocols: ['postgres'],
480+
require_host: false,
481+
}],
482+
valid: [
483+
'postgres://user:pw@/test',
484+
],
485+
invalid: [
486+
'http://foobar.com',
487+
'postgres://',
488+
],
489+
});
490+
});
491+
492+
475493
it('should validate URLs with any protocol', () => {
476494
test({
477495
validator: 'isURL',

0 commit comments

Comments
 (0)