@@ -310,6 +310,7 @@ keywordHandlers["https://json-schema.org/keyword/propertyNames"] = {
310310 return outputs ;
311311 }
312312 for ( const propertyName of Instance . keys ( instance ) ) {
313+ propertyName . pointer = propertyName . pointer . replace ( / ^ \* / , "" ) ;
313314 outputs . push ( evaluateSchema ( propertyNamesSchemaLocation , propertyName , context ) ) ;
314315 }
315316 return outputs ;
@@ -657,7 +658,7 @@ export const constructErrorIndex = async (outputUnit, schema, errorIndex = {}) =
657658 }
658659 const absoluteKeywordLocation = errorOutputUnit . absoluteKeywordLocation
659660 ?? 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 ) ) ;
661662 errorIndex [ absoluteKeywordLocation ] ??= { } ;
662663 errorIndex [ absoluteKeywordLocation ] [ instanceLocation ] = true ;
663664 await constructErrorIndex ( errorOutputUnit , schema , errorIndex ) ;
@@ -677,27 +678,10 @@ export async function toAbsoluteKeywordLocation(schema, keywordLocation) {
677678 return `${ schema . document . baseUri } #${ schema . cursor } ` ;
678679}
679680
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/" ) ;
701685}
702686
703687/**
0 commit comments