Skip to content

bug(codegen): ajv/standalone per-property type guards miscompile (invalid input accepted) #1803

Description

@proggeramlug

Summary

Perry miscompiles the per-property type guards in ajv's standalone-generated validators: for a schema with typed properties, invalid inputs are accepted as valid. Surfaced by #1680.

Repro (via ajv/standalone output)

Schema:

{ $id: "User", type: "object",
  properties: { name: { type: "string" }, age: { type: "number" }, active: { type: "boolean" } },
  required: ["name", "age"], additionalProperties: false }

Generate the standalone validator with new Ajv({ code: { source: true } }) + standaloneCode(...), import it, and run:

validate({ name: "Ada", age: "old" });   // node: false (age not a number) — perry: true
validate({ name: "Ada", age: 5, active: "yes" }); // node: false (active not boolean) — perry: true
validate({ name: "Ada", age: 1.5 });     // (integer schema) node: false — perry: true

type: string rejection works for a number value but not a boolean; type: number/type: boolean/type: integer rejection fail. The structural subset (object / required / additionalProperties, empty property schemas) is fully parity-clean — see test-files/test_ajv_standalone.ts.

Notes

Minimal repros of the individual pieces (typeof v !== "string" on a boolean param-property, x % 1 on a float) pass in isolation, so this is an interaction within ajv's dense generated structure (const _errs = errors; … if(errors === _errs){ … } nesting around each property guard), not one of those primitives alone. The generated validator file is the concrete repro. Blocks full-coverage ajv under #1680; the structural subset is unblocked.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew capability or improvement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions