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

JSON parsing fails for v8 versions 11.7.72 and newer #2355

Closed
egfx-notifications opened this issue Dec 20, 2023 · 1 comment · Fixed by #2356
Closed

JSON parsing fails for v8 versions 11.7.72 and newer #2355

egfx-notifications opened this issue Dec 20, 2023 · 1 comment · Fixed by #2356

Comments

@egfx-notifications
Copy link
Contributor

What version of Ajv are you using? Does the issue happen if you use the latest version?
v8.12.0

Ajv options object
not used

JSON Schema

{
  "properties": {
    "test": { "type": "uint8" }
  },
  "additionalProperties": true
}

Sample data

{
      "test": 1,
      "error": "now"
}

Your code

const Ajv = require("ajv/dist/jtd");

const JTDschema = {
  properties: {
    test: { type: "uint8" },
  },
  additionalProperties: true,
};

const payload = `{
        "test": 1,
        "error": "now"
  }`;

const ajv = new Ajv();

const parser = ajv.compileParser(JTDschema);

const output = parser(payload);

if (!output) {
  console.log(parser.position);
  console.log(parser.message);
}

Console output

47
unexpected end

What results did you expect?
Validates successfully, no console output

Are you going to resolve the issue?
Yes, patch is already written, PR incoming

Additional context
v8 11.7.72 changed the message templates for JSON parsing related error messages (https://chromium-review.googlesource.com/c/v8/v8/+/4652014)
This breaks parseJson() and leads to parsing errors if utilizing additionalProperties in a JSONTypeDefinition (other issues not specifically tested).
npm test also produces several errors with the mentioned v8 version.
This can be tested with NodeJS v21.0.0 or newer and deno v1.36.1 or newer since those versions updated their respective v8 versions past the affected version

@epoberezkin
Copy link
Member

Needs to be fixed once confirmed

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

Successfully merging a pull request may close this issue.

2 participants