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 4
4
* Module dependencies.
5
5
*/
6
6
7
+ const _ = require ( 'lodash' ) ;
7
8
const { Validator, Violation } = require ( 'validator.js' ) ;
8
9
const { forEach, has } = require ( 'lodash' ) ;
9
10
@@ -52,7 +53,7 @@ module.exports = function uriAssert(constraints) {
52
53
const uri = new URI ( value ) ;
53
54
54
55
// URIs must have at least a hostname and protocol.
55
- if ( ! uri . hostname ( ) || ! uri . protocol ( ) ) {
56
+ if ( _ . isEmpty ( this . constraints ) && ( ! uri . hostname ( ) || ! uri . protocol ( ) ) ) {
56
57
throw new Violation ( this , value , { constraints : this . constraints } ) ;
57
58
}
58
59
Original file line number Diff line number Diff line change @@ -106,6 +106,10 @@ describe('UriAssert', () => {
106
106
}
107
107
} ) ;
108
108
109
+ it ( 'should accept an `is` constraint without a hostname or protocol' , ( ) => {
110
+ Assert . uri ( { is : 'relative' } ) . validate ( '/dashboard' ) ;
111
+ } ) ;
112
+
109
113
it ( 'should accept an uri that matches the constraints' , ( ) => {
110
114
Assert . uri ( { is : 'domain' } ) . validate ( 'https://foobar.com' ) ;
111
115
Assert . uri ( { protocol : 'https' } ) . validate ( 'https://foobar.com' ) ;
You can’t perform that action at this time.
0 commit comments