Skip to content

Commit

Permalink
fix urijs fragment handling incompatibility (#93)
Browse files Browse the repository at this point in the history
* fix uri-js incompatibilities

* fix the error

* fix

* fix error
  • Loading branch information
gurgunday committed Jun 27, 2024
1 parent 5964558 commit b16b747
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
39 changes: 39 additions & 0 deletions test/ajv.test.js
Original file line number Diff line number Diff line change
@@ -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<string,Person>': {
type: 'object',
additionalProperties: {
$ref: '#/definitions/Person'
}
}
}
}

const data = {
joe: {
firstName: 'Joe'
}

}

const validate = ajv.compile(schema)
t.ok(validate(data))
})

0 comments on commit b16b747

Please sign in to comment.