Skip to content

Commit 7beca67

Browse files
authored
Make sure to encode values in query and path parameters (#219)
1 parent bb3c4fb commit 7beca67

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

packages/docusaurus-theme-openapi/src/theme/ApiDemoPanel/buildPostmanRequest.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function setQueryParams(postman: sdk.Request, queryParams: Param[]) {
2929
if (Array.isArray(param.value)) {
3030
return new sdk.QueryParam({
3131
key: param.name,
32-
value: param.value.join(","),
32+
value: param.value.map(encodeURIComponent).join(","),
3333
});
3434
}
3535

@@ -46,7 +46,7 @@ function setQueryParams(postman: sdk.Request, queryParams: Param[]) {
4646

4747
return new sdk.QueryParam({
4848
key: param.name,
49-
value: param.value,
49+
value: encodeURIComponent(param.value),
5050
});
5151
})
5252
.filter((item): item is sdk.QueryParam => item !== undefined);
@@ -57,10 +57,15 @@ function setQueryParams(postman: sdk.Request, queryParams: Param[]) {
5757
}
5858

5959
function setPathParams(postman: sdk.Request, queryParams: Param[]) {
60+
const recursiveEncodeURIComponent = (c: string | string[]) =>
61+
Array.isArray(c) ? c.map(encodeURIComponent) : encodeURIComponent(c);
62+
6063
const source = queryParams.map((param) => {
6164
return new sdk.Variable({
6265
key: param.name,
63-
value: param.value || `:${param.name}`,
66+
value: param.value
67+
? recursiveEncodeURIComponent(param.value)
68+
: `:${param.name}`,
6469
});
6570
});
6671
postman.url.variables.assimilate(source, false);

0 commit comments

Comments
 (0)