@@ -312,23 +312,22 @@ const getInvalidProperty = (error: ErrorObject): string | undefined => {
312
312
313
313
export const getControlPath = ( error : ErrorObject ) => {
314
314
const dataPath = ( error as any ) . dataPath ;
315
+ console . log ( "datapath: " , dataPath ) ;
315
316
// older AJV version
316
317
if ( dataPath ) {
317
- return dataPath . replace ( / \/ / g, '.' ) . substr ( 1 ) ;
318
+ return dataPath . split ( " /\//g" ) . filter ( ( e : string ) => e !== "" ) ;
318
319
}
319
320
// dataPath was renamed to instancePath in AJV v8
320
- var controlPath : string = error . instancePath ;
321
-
322
321
// change '/' chars to '.'
323
- controlPath = controlPath . replace ( / \/ / g, '.' ) ;
322
+ console . log ( "instancePath: " , error . instancePath ) ;
323
+ var controlPath : string [ ] = error . instancePath . split ( "/" ) . filter ( e => e !== "" ) ;
324
324
325
325
const invalidProperty = getInvalidProperty ( error ) ;
326
- if ( invalidProperty !== undefined && ! controlPath . endsWith ( invalidProperty ) ) {
327
- controlPath = ` ${ controlPath } . ${ invalidProperty } ` ;
326
+ if ( invalidProperty !== undefined && controlPath && controlPath [ controlPath . length ] !== invalidProperty ) {
327
+ controlPath . push ( invalidProperty ) ;
328
328
}
329
329
330
- // remove '.' chars at the beginning of paths
331
- controlPath = controlPath . replace ( / ^ ./ , '' ) ;
330
+ console . log ( "returnedPath: " , controlPath ) ;
332
331
return controlPath ;
333
332
}
334
333
@@ -400,6 +399,7 @@ const getErrorsAt = (
400
399
errorsAt ( instancePath , schema , matchPath ) ( state . validationMode === 'ValidateAndHide' ? [ ] : state . errors ) ;
401
400
402
401
export const errorAt = ( instancePath : string [ ] , schema : JsonSchema ) =>
403
- getErrorsAt ( instancePath , schema , path => path === instancePath ) ;
402
+ getErrorsAt ( instancePath , schema , p => {
403
+ return p . length === instancePath . length && p . every ( ( element , i ) => element === instancePath [ i ] ) } ) ;
404
404
export const subErrorsAt = ( instancePath : string [ ] , schema : JsonSchema ) =>
405
405
getErrorsAt ( instancePath , schema , path => contains ( path , instancePath ) ) ;
0 commit comments