From d0baaa60eecb1e797c439cc10016503bac5b20e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Sun, 23 Jun 2024 07:45:27 +0300 Subject: [PATCH 1/4] fix uri-js incompatibilities --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 7a7b4d3..ac1e908 100644 --- a/index.js +++ b/index.js @@ -130,7 +130,7 @@ function serialize (cmpts, opts) { components.path = components.path.split('%3A').join(':') } } else { - components.path = unescape(components.path) + components.path = decodeURIComponent(components.path) } } From 0bec2d19f9bb7a3b9f1def06d794f9966a25ced3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Wed, 26 Jun 2024 15:24:36 +0300 Subject: [PATCH 2/4] fix the 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 ac1e908..2a52d4c 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(unescape(parsed.fragment)) } } diff --git a/package.json b/package.json index 44e13df..bf62a25 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "test:ci": "npm run test:lint && npm run test:unit -- --cov --coverage-report=lcovonly && npm run test:typescript" }, "devDependencies": { + "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)) +}) From 46ec9245ec78a61f5b6dabf003375162f3581810 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Wed, 26 Jun 2024 15:26:28 +0300 Subject: [PATCH 3/4] fix --- index.js | 2 +- package.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 2a52d4c..9aaa031 100644 --- a/index.js +++ b/index.js @@ -130,7 +130,7 @@ function serialize (cmpts, opts) { components.path = components.path.split('%3A').join(':') } } else { - components.path = decodeURIComponent(components.path) + components.path = unescape(components.path) } } diff --git a/package.json b/package.json index 7f15180..12e082e 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "test:typescript": "tsd" }, "devDependencies": { + "@fastify/pre-commit": "^2.1.0", "ajv": "^8.16.0", "benchmark": "^2.1.4", "coveralls": "^3.1.1", From 63509a8303adda41fa69a563e428d68bd66e65c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Wed, 26 Jun 2024 15:31:56 +0300 Subject: [PATCH 4/4] fix error --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 9aaa031..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(unescape(parsed.fragment)) + parsed.fragment = encodeURI(decodeURIComponent(parsed.fragment)) } }