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) {
152
152
if ( options . host_whitelist ) {
153
153
return checkHost ( host , options . host_whitelist ) ;
154
154
}
155
+
156
+ if ( host === '' && ! options . require_host ) {
157
+ return true ;
158
+ }
159
+
155
160
if ( ! isIP ( host ) && ! isFQDN ( host , options ) && ( ! ipv6 || ! isIP ( ipv6 , 6 ) ) ) {
156
161
return false ;
157
162
}
Original file line number Diff line number Diff line change @@ -472,6 +472,24 @@ describe('Validators', () => {
472
472
} ) ;
473
473
} ) ;
474
474
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
+
475
493
it ( 'should validate URLs with any protocol' , ( ) => {
476
494
test ( {
477
495
validator : 'isURL' ,
You can’t perform that action at this time.
0 commit comments