@@ -48,6 +48,7 @@ import type {
48
48
ErrorObject ,
49
49
Format ,
50
50
AddedFormat ,
51
+ RegExpEngine ,
51
52
} from "./types"
52
53
import type { JSONSchemaType } from "./types/json-schema"
53
54
import type { JTDSchemaType , SomeJTDSchemaType , JTDDataType } from "./types/jtd-schema"
@@ -62,6 +63,9 @@ import {eachItem} from "./compile/util"
62
63
63
64
import * as $dataRefSchema from "./refs/data.json"
64
65
66
+ const defaultRegExp : RegExpEngine = ( str , flags ) => new RegExp ( str , flags )
67
+ defaultRegExp . code = "new RegExp"
68
+
65
69
const META_IGNORE_OPTIONS : ( keyof Options ) [ ] = [ "removeAdditional" , "useDefaults" , "coerceTypes" ]
66
70
const EXT_SCOPE_NAMES = new Set ( [
67
71
"validate" ,
@@ -141,9 +145,11 @@ export interface CodeOptions {
141
145
formats ?: Code // code to require (or construct) map of available formats - for standalone code
142
146
source ?: boolean
143
147
process ?: ( code : string , schema ?: SchemaEnv ) => string
148
+ regExp ?: RegExpEngine
144
149
}
145
150
146
151
interface InstanceCodeOptions extends CodeOptions {
152
+ regExp : RegExpEngine
147
153
optimize : number
148
154
}
149
155
@@ -231,13 +237,14 @@ function requiredOptions(o: Options): RequiredInstanceOptions {
231
237
const s = o . strict
232
238
const _optz = o . code ?. optimize
233
239
const optimize = _optz === true || _optz === undefined ? 1 : _optz || 0
240
+ const regExp = o . code ?. regExp ?? defaultRegExp
234
241
return {
235
242
strictSchema : o . strictSchema ?? s ?? true ,
236
243
strictNumbers : o . strictNumbers ?? s ?? true ,
237
244
strictTypes : o . strictTypes ?? s ?? "log" ,
238
245
strictTuples : o . strictTuples ?? s ?? "log" ,
239
246
strictRequired : o . strictRequired ?? s ?? false ,
240
- code : o . code ? { ...o . code , optimize} : { optimize} ,
247
+ code : o . code ? { ...o . code , optimize, regExp } : { optimize, regExp } ,
241
248
loopRequired : o . loopRequired ?? MAX_EXPRESSION ,
242
249
loopEnum : o . loopEnum ?? MAX_EXPRESSION ,
243
250
meta : o . meta ?? true ,
@@ -279,6 +286,7 @@ export default class Ajv {
279
286
constructor ( opts : Options = { } ) {
280
287
opts = this . opts = { ...opts , ...requiredOptions ( opts ) }
281
288
const { es5, lines} = this . opts . code
289
+
282
290
this . scope = new ValueScope ( { scope : { } , prefixes : EXT_SCOPE_NAMES , es5, lines} )
283
291
this . logger = getLogger ( opts . logger )
284
292
const formatOpt = opts . validateFormats
0 commit comments