From b16b7477140571cf053343cfebb356a756e5c0b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Thu, 27 Jun 2024 10:31:17 +0300 Subject: [PATCH] fix `urijs` fragment handling incompatibility (#93) * fix uri-js incompatibilities * fix the error * fix * fix error --- index.js | 2 +- package.json | 1 + test/ajv.test.js | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 test/ajv.test.js diff --git a/index.js b/index.js index 7a7b4d3..2ca8173 100644 --- a/index.js +++ b/index.js @@ -280,7 +280,7 @@ function parse (uri, opts) { parsed.path = escape(unescape(parsed.path)) } if (parsed.fragment !== undefined && parsed.fragment.length) { - parsed.fragment = encodeURI(decodeURI(parsed.fragment)) + parsed.fragment = encodeURI(decodeURIComponent(parsed.fragment)) } } diff --git a/package.json b/package.json index c6931d7..12e082e 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ }, "devDependencies": { "@fastify/pre-commit": "^2.1.0", + "ajv": "^8.16.0", "benchmark": "^2.1.4", "coveralls": "^3.1.1", "snazzy": "^9.0.0", diff --git a/test/ajv.test.js b/test/ajv.test.js new file mode 100644 index 0000000..42ecb45 --- /dev/null +++ b/test/ajv.test.js @@ -0,0 +1,39 @@ +const AJV = require('ajv') +const fastUri = require('../') +const ajv = new AJV({ + uriResolver: fastUri // comment this line to see it works with uri-js +}) +const { test } = require('tap') + +test('ajv', t => { + t.plan(1) + const schema = { + $ref: '#/definitions/Record%3Cstring%2CPerson%3E', + definitions: { + Person: { + type: 'object', + properties: { + firstName: { + type: 'string' + } + } + }, + 'Record': { + type: 'object', + additionalProperties: { + $ref: '#/definitions/Person' + } + } + } + } + + const data = { + joe: { + firstName: 'Joe' + } + + } + + const validate = ajv.compile(schema) + t.ok(validate(data)) +})