@@ -21,8 +21,6 @@ import { readFile } from 'node:fs/promises'
2121
2222import Ajv , { type Options as AjvOptions } from 'ajv'
2323import addFormats from 'ajv-formats'
24- /* @ts -expect-error TS7016 */
25- import addFormats2019 from 'ajv-formats-draft2019'
2624
2725import type { ValidationError } from '../../validation/types'
2826import type { Functionality , Validator } from '../jsonValidator'
@@ -50,11 +48,19 @@ export default (async function (schemaPath: string, schemaMap: Record<string, st
5048 /* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- intended */
5149 const ajv = new Ajv ( { ...ajvOptions , schemas } )
5250 addFormats ( ajv )
53- /* eslint-disable-next-line @typescript-eslint/no-unsafe-call -- intended */
54- addFormats2019 ( ajv , { formats : [ 'idn-email' ] } )
51+
5552 // there is just no working implementation for format "iri-reference": see https://github.com/luzlab/ajv-formats-draft2019/issues/22
5653 ajv . addFormat ( 'iri-reference' , true )
5754
55+ // add idn-email format (was previously provided by ajv-formats-draft2019)
56+ const emailValidator = ajv . compile ( { type : 'string' , format : 'email' } )
57+ ajv . addFormat ( 'idn-email' , {
58+ type : 'string' ,
59+ // syntax allows non-ASCII characters in places where 'x' would be allowed
60+ // (don't attempt to validate exactly which Unicode characters are OK - too complex)
61+ validate : x => emailValidator ( x . replace ( / [ \u0080 - \uffff ] + / g, 'x' ) )
62+ } )
63+
5864 const validator = ajv . compile ( schema )
5965
6066 return function ( data : string ) : null | ValidationError {
0 commit comments