From 749499269ef077fd2363e372e1f27312c3804f96 Mon Sep 17 00:00:00 2001 From: Jason Green Date: Wed, 12 Jun 2024 22:53:32 +0100 Subject: [PATCH] test: add encoded ref test --- lib/compile/codegen/code.ts | 1 + spec/resolve.spec.ts | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/lib/compile/codegen/code.ts b/lib/compile/codegen/code.ts index b17701973e..9d4de6149f 100644 --- a/lib/compile/codegen/code.ts +++ b/lib/compile/codegen/code.ts @@ -1,3 +1,4 @@ +// eslint-disable-next-line @typescript-eslint/no-extraneous-class export abstract class _CodeOrName { abstract readonly str: string abstract readonly names: UsedNames diff --git a/spec/resolve.spec.ts b/spec/resolve.spec.ts index a89cccaf72..35a5a0ad2e 100644 --- a/spec/resolve.spec.ts +++ b/spec/resolve.spec.ts @@ -16,7 +16,7 @@ uriResolvers.forEach((resolver) => { } else { describeTitle = "fast-uri resolver" } - describe(describeTitle, () => { + describe.only(describeTitle, () => { describe("resolve", () => { let instances: AjvCore[] @@ -180,6 +180,41 @@ uriResolvers.forEach((resolver) => { }) }) + describe("URIs with encoded characters (issue #2447)", () => { + it("should resolve the ref", () => { + const 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": { + type: "object", + additionalProperties: { + $ref: "#/definitions/Person", + }, + }, + }, + } + const data = { + joe: { + firstName: "Joe", + }, + } + instances.forEach((ajv) => { + const validate = ajv.compile(schema) + validate(data).should.equal(true) + }) + }) + }) + describe("missing schema error", function () { this.timeout(4000)