File tree Expand file tree Collapse file tree 2 files changed +6
-1
lines changed Expand file tree Collapse file tree 2 files changed +6
-1
lines changed Original file line number Diff line number Diff line change 44 * Module dependencies.
55 */
66
7+ const _ = require ( 'lodash' ) ;
78const { Validator, Violation } = require ( 'validator.js' ) ;
89const { forEach, has } = require ( 'lodash' ) ;
910
@@ -52,7 +53,7 @@ module.exports = function uriAssert(constraints) {
5253 const uri = new URI ( value ) ;
5354
5455 // URIs must have at least a hostname and protocol.
55- if ( ! uri . hostname ( ) || ! uri . protocol ( ) ) {
56+ if ( _ . isEmpty ( this . constraints ) && ( ! uri . hostname ( ) || ! uri . protocol ( ) ) ) {
5657 throw new Violation ( this , value , { constraints : this . constraints } ) ;
5758 }
5859
Original file line number Diff line number Diff line change @@ -106,6 +106,10 @@ describe('UriAssert', () => {
106106 }
107107 } ) ;
108108
109+ it ( 'should accept an `is` constraint without a hostname or protocol' , ( ) => {
110+ Assert . uri ( { is : 'relative' } ) . validate ( '/dashboard' ) ;
111+ } ) ;
112+
109113 it ( 'should accept an uri that matches the constraints' , ( ) => {
110114 Assert . uri ( { is : 'domain' } ) . validate ( 'https://foobar.com' ) ;
111115 Assert . uri ( { protocol : 'https' } ) . validate ( 'https://foobar.com' ) ;
You can’t perform that action at this time.
0 commit comments