Skip to content

Commit

Permalink
fix(parameters): decode path parameters
Browse files Browse the repository at this point in the history
Percent encoded special characters in path parameter are decoded.

With a route `api/{file}` the request URL
`api/test%20one` the value of `$request?parameters?file`  will be "test one".
  • Loading branch information
line-o committed Jul 12, 2023
1 parent 759288a commit ff8b51c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions content/parameters.xql
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ declare function parameters:in-path ($request as map(*), $response as map(*)) as
then (
let $value :=
$match-path//fn:group[@nr=$pos]/string()
=> xmldb:decode()
=> parameters:cast($path-param-map?($key))

return map { $key : $value }
Expand Down
29 changes: 29 additions & 0 deletions test/app/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,35 @@
}
}
},
"/api/{test}/test":{
"get": {
"summary": "Get path with a fixed ending",
"operationId": "rutil:debug",
"tags": ["path"],
"parameters": [
{
"name": "test",
"in": "path",
"required": true,
"schema":{
"type": "string"
}
}
],
"responses": {
"200":{
"description": "JSON dump of request",
"content": {
"application/json": {
"schema":{
"type": "object"
}
}
}
}
}
}
},
"/api/errors": {
"get": {
"summary": "Reports an error via fn:error function",
Expand Down
17 changes: 17 additions & 0 deletions test/paths.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,20 @@ describe('Query parameters', function () {
expect(res.data).to.be.true
})
})

describe('with percent encoded value in path', function () {
const url = 'api/test%20and%20test/test'
let res

before(async function () {
res = await util.axios.get(url)
})

it('URL + "' + url + '" resolves', async function () {
expect(res.status).to.equal(200)
})

it('passes query parameters in GET', async function () {
expect(res.data.parameters.test).to.equal('test and test')
})
})

0 comments on commit ff8b51c

Please sign in to comment.