File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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' ,
You can’t perform that action at this time.
0 commit comments