@@ -110,9 +110,14 @@ var isMultipleOf = function(name, multipleOf) {
110
110
return ! res ;
111
111
}
112
112
113
+ var testLimitedRegex = function ( r , s , maxLength ) {
114
+ if ( maxLength > - 1 && s . length > maxLength ) return true
115
+ return r . test ( s )
116
+ }
117
+
113
118
var compile = function ( schema , cache , root , reporter , opts ) {
114
119
var fmts = opts ? xtend ( formats , opts . formats ) : formats
115
- var scope = { unique :unique , formats :fmts , isMultipleOf :isMultipleOf }
120
+ var scope = { unique :unique , formats :fmts , isMultipleOf :isMultipleOf , testLimitedRegex : testLimitedRegex }
116
121
var verbose = opts ? ! ! opts . verbose : false ;
117
122
var greedy = opts && opts . greedy !== undefined ?
118
123
opts . greedy : false ;
@@ -218,7 +223,7 @@ var compile = function(schema, cache, root, reporter, opts) {
218
223
scope [ n ] = fmts [ node . format ]
219
224
220
225
if ( typeof scope [ n ] === 'function' ) validate ( 'if (!%s(%s)) {' , n , name )
221
- else validate ( 'if (!%s.test(%s )) {' , n , name )
226
+ else validate ( 'if (!testLimitedRegex(%s, %s, %d )) {' , n , name , typeof node . maxLength === 'undefined' ? - 1 : node . maxLength )
222
227
error ( 'must be ' + node . format + ' format' )
223
228
validate ( '}' )
224
229
if ( type !== 'string' && formats [ node . format ] ) validate ( '}' )
@@ -392,7 +397,7 @@ var compile = function(schema, cache, root, reporter, opts) {
392
397
if ( node . pattern ) {
393
398
var p = patterns ( node . pattern )
394
399
if ( type !== 'string' ) validate ( 'if (%s) {' , types . string ( name ) )
395
- validate ( 'if (!(%s.test(%s ))) {' , p , name )
400
+ validate ( 'if (!(testLimitedRegex(%s, %s, %d ))) {' , p , name , typeof node . maxLength === 'undefined' ? - 1 : node . maxLength )
396
401
error ( 'pattern mismatch' )
397
402
validate ( '}' )
398
403
if ( type !== 'string' ) validate ( '}' )
0 commit comments