@@ -310,6 +310,7 @@ keywordHandlers["https://json-schema.org/keyword/propertyNames"] = {
310
310
return outputs ;
311
311
}
312
312
for ( const propertyName of Instance . keys ( instance ) ) {
313
+ propertyName . pointer = propertyName . pointer . replace ( / ^ \* / , "" ) ;
313
314
outputs . push ( evaluateSchema ( propertyNamesSchemaLocation , propertyName , context ) ) ;
314
315
}
315
316
return outputs ;
@@ -657,7 +658,7 @@ export const constructErrorIndex = async (outputUnit, schema, errorIndex = {}) =
657
658
}
658
659
const absoluteKeywordLocation = errorOutputUnit . absoluteKeywordLocation
659
660
?? await toAbsoluteKeywordLocation ( schema , /** @type string */ ( errorOutputUnit . keywordLocation ) ) ;
660
- const instanceLocation = /** @type string */ ( normalizeInstanceLocation ( errorOutputUnit . instanceLocation , errorOutputUnit . absoluteKeywordLocation ) ) ;
661
+ const instanceLocation = normalizeInstanceLocation ( /** @type string */ ( errorOutputUnit . instanceLocation ) ) ;
661
662
errorIndex [ absoluteKeywordLocation ] ??= { } ;
662
663
errorIndex [ absoluteKeywordLocation ] [ instanceLocation ] = true ;
663
664
await constructErrorIndex ( errorOutputUnit , schema , errorIndex ) ;
@@ -677,27 +678,10 @@ export async function toAbsoluteKeywordLocation(schema, keywordLocation) {
677
678
return `${ schema . document . baseUri } #${ schema . cursor } ` ;
678
679
}
679
680
680
- /** @type {(location: string | undefined, keywordLocation: string | undefined) => string | undefined } */
681
- function normalizeInstanceLocation ( location , keywordLocation ) {
682
- if ( typeof location !== "string" ) {
683
- return location ;
684
- }
685
-
686
- if ( location . includes ( "*/" ) ) {
687
- return location . startsWith ( "#" ) ? location : `#${ location } ` ;
688
- }
689
-
690
- const isPropertyNameError = keywordLocation ?. includes ( "/propertyNames/" ) ;
691
- const purePointer = location . startsWith ( "#" ) ? location . substring ( 1 ) : location ;
692
-
693
- if ( isPropertyNameError ) {
694
- const segments = [ ...pointerSegments ( purePointer ) ] ;
695
- const key = segments . pop ( ) ?? "" ;
696
- const parentPath = segments . join ( "/" ) ;
697
- return `#${ parentPath } */${ key } ` ;
698
- } else {
699
- return `#${ purePointer } ` ;
700
- }
681
+ /** @type {(location: string) => string } */
682
+ function normalizeInstanceLocation ( location ) {
683
+ const instanceLocation = location . startsWith ( "/" ) || location === "" ? `#${ location } ` : location ;
684
+ return instanceLocation . replace ( / ( # | ^ ) \* \/ / , "$1/" ) ;
701
685
}
702
686
703
687
/**
0 commit comments