Handling of URL encoding changed/broke in 8.15
joshkel opened this issue · 6 comments
What version of Ajv are you using? Does the issue happen if you use the latest version?
8.15 (latest version)
Ajv options object
const ajv = new AJV();
JSON Schema
{
"$ref": "#/definitions/Record%3Cstring%2CPerson%3E",
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"Person": {
"type": "object",
"properties": {
"firstName": {
"type": "string",
"description": "The person's first name."
}
}
}
"Record<string,Person>": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/Person"
}
}
}
}
Sample data
{
"joe": {
"firstName": "Joe"
}
}
Your code
const AJV = require('ajv');
const ajv = new AJV(options);
const validate = ajv.compile(schema);
console.log(validate(data));
Validation result, data AFTER validation, error messages
Compiler error:
MissingRefError: can't resolve reference #/definitions/Record%3Cstring%2CPerson%3E from id #
at Object.code (node_modules/ajv/dist/vocabularies/core/ref.js:21:19)
at keywordCode (node_modules/ajv/dist/compile/validate/index.js:464:13)
at node_modules/ajv/dist/compile/validate/index.js:185:25
at CodeGen.code (node_modules/ajv/dist/compile/codegen/index.js:439:13)
at CodeGen.block (node_modules/ajv/dist/compile/codegen/index.js:568:18)
at schemaKeywords (node_modules/ajv/dist/compile/validate/index.js:185:13)
at typeAndKeywords (node_modules/ajv/dist/compile/validate/index.js:128:5)
at node_modules/ajv/dist/compile/validate/index.js:70:9
at CodeGen.code (node_modules/ajv/dist/compile/codegen/index.js:439:13)
at node_modules/ajv/dist/compile/validate/index.js:37:166 {
missingRef: '#/definitions/Record%3Cstring%252CPerson%3E',
missingSchema: ''
}
What results did you expect?
Successful compilation of the schema. This worked in 8.14 and works in https://www.jsonschemavalidator.net/, but 8.15's change of URL library seems to have altered its behavior.
Are you going to resolve the issue?
I know that 8.15's URL parser changes are actively being worked on, but I can help if needed.
Encountering this same issue since last night and was wondering why my builds are failing.
Reverting now. New version will be 8.16.0 and will set everything back to how it was in 8.14.0. Sorry for the disruption.
Reverted in v8.16.0
I will close this but keep this as a reference when considering how best to deal with uri-js.
Thanks for the quick fix, @jasoniangreen.
I can confirm that 8.16.0 works fine for all my use cases. Thanks!
I'm currently investigating this - just noting that if you do not preencode your $ref, it works correctly, and from the output, it seems like we double encode and not decode later or decode incorrectly