Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling of URL encoding changed/broke in 8.15 #2447

Closed
joshkel opened this issue Jun 4, 2024 · 6 comments
Closed

Handling of URL encoding changed/broke in 8.15 #2447

joshkel opened this issue Jun 4, 2024 · 6 comments

Comments

@joshkel
Copy link

joshkel commented Jun 4, 2024

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.

@damain
Copy link

damain commented Jun 4, 2024

Encountering this same issue since last night and was wondering why my builds are failing.

https://github.com/ajv-validator/ajv/releases/tag/v8.15.0

@jasoniangreen
Copy link
Collaborator

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.

@jasoniangreen
Copy link
Collaborator

Reverted in v8.16.0

I will close this but keep this as a reference when considering how best to deal with uri-js.

@joshkel
Copy link
Author

joshkel commented Jun 4, 2024

Thanks for the quick fix, @jasoniangreen.

@errodrigues
Copy link

I can confirm that 8.16.0 works fine for all my use cases. Thanks!

@gurgunday
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants