Skip to content

Commit

Permalink
Fix unresolved location if some key in data contains slash
Browse files Browse the repository at this point in the history
  • Loading branch information
jirutka committed Jun 25, 2024
1 parent f3e5625 commit acafb2b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/commands/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { ProgramError } from '../errors.js'
import { type ParsedFile, parseFile, parseFileWithMeta } from '../parsers/index.js'
import { getSimpleErrors } from '../vendor/simple-ajv-errors/index.js'
import type { VerboseErrorObject } from '../vendor/simple-ajv-errors/types.js'
import { expandFilePaths, sha1sum } from '../utils.js'
import { expandFilePaths, sha1sum, unescapeJsonPointer } from '../utils.js'
import type { LocationRange, ValidationError } from '../types.js'

const optionsSchema = {
Expand Down Expand Up @@ -251,7 +251,7 @@ function withInstanceLocation<T extends ValidationError>(
...err,
instanceLocation: {
filename: file.filename,
...file.locate(err.instancePath.split('/').slice(1)),
...file.locate(err.instancePath.split('/').slice(1).map(unescapeJsonPointer)),
},
}))
}
4 changes: 4 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ export function sanitizeId(input: string): string {
export function sha1sum(data: unknown): string {
return crypto.createHash('sha1').update(JSON.stringify(data)).digest('hex')
}

export function unescapeJsonPointer(pointer: string): string {
return pointer.replaceAll('~1', '/').replaceAll('~0', '~')
}

0 comments on commit acafb2b

Please sign in to comment.