Skip to content

Commit

Permalink
Merge pull request #1995 from mortbauer/fix/isURL-empty-host-with-query
Browse files Browse the repository at this point in the history
do not check if the host is valid if no host is specified and not require_host
  • Loading branch information
rubiin committed Jul 17, 2022
2 parents d5f8015 + 5d2ff83 commit 9f89f3b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lib/isURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ export default function isURL(url, options) {
if (options.host_whitelist) {
return checkHost(host, options.host_whitelist);
}

if (host === '' && !options.require_host) {
return true;
}

if (!isIP(host) && !isFQDN(host, options) && (!ipv6 || !isIP(ipv6, 6))) {
return false;
}
Expand Down
18 changes: 18 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,24 @@ describe('Validators', () => {
});
});

it('should validate postgres URLs without a host', () => {
test({
validator: 'isURL',
args: [{
protocols: ['postgres'],
require_host: false,
}],
valid: [
'postgres://user:pw@/test',
],
invalid: [
'http://foobar.com',
'postgres://',
],
});
});


it('should validate URLs with any protocol', () => {
test({
validator: 'isURL',
Expand Down

0 comments on commit 9f89f3b

Please sign in to comment.