Skip to content

Commit 5fdee72

Browse files
authored
fix(explorer): encode RFC 3986 reserved chars in query parameter values (#1366)
* fix(explorer): encode RFC 3986 reserved chars in query parameter values Replaces the manual space-only encoding with encodeURIComponent for query parameters, so reserved characters like ':' are correctly percent-encoded (e.g. ':' → '%3A') when building request URLs. Path parameters retain the existing whitespace-only encoding since they are handled separately downstream in setPathParams. Closes #1312 * test(explorer): add RFC 3986 query param encoding cases to paramSerialization Adds two endpoints to visually verify that reserved characters like ':', '/', and '#' are percent-encoded in query parameter values. Related to #1312
1 parent 216d6bd commit 5fdee72

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

demo/examples/tests/paramSerialization.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,64 @@ paths:
420420
"200":
421421
description: Successful response
422422

423+
/rfc3986/colon:
424+
get:
425+
tags:
426+
- params
427+
summary: Query param with RFC 3986 reserved char ':'
428+
description: |
429+
Verifies that `:` in a query parameter value is percent-encoded as `%3A`.
430+
431+
Example:
432+
```
433+
filter = "status:active"
434+
Result: /rfc3986/colon?filter=status%3Aactive
435+
```
436+
parameters:
437+
- name: filter
438+
in: query
439+
description: 'Try a value containing a colon, e.g. "status:active"'
440+
schema:
441+
type: string
442+
responses:
443+
"200":
444+
description: Successful response
445+
446+
/rfc3986/reserved:
447+
get:
448+
tags:
449+
- params
450+
summary: Query params with multiple RFC 3986 reserved chars
451+
description: |
452+
Verifies that RFC 3986 reserved characters in query parameter values
453+
are percent-encoded correctly.
454+
455+
Example:
456+
```
457+
q = "hello:world" → q=hello%3Aworld
458+
path = "a/b/c" → path=a%2Fb%2Fc
459+
ref = "v1#section" → ref=v1%23section
460+
```
461+
parameters:
462+
- name: q
463+
in: query
464+
description: 'Try a value with a colon, e.g. "hello:world"'
465+
schema:
466+
type: string
467+
- name: path
468+
in: query
469+
description: 'Try a value with slashes, e.g. "a/b/c"'
470+
schema:
471+
type: string
472+
- name: ref
473+
in: query
474+
description: 'Try a value with a hash, e.g. "v1#section"'
475+
schema:
476+
type: string
477+
responses:
478+
"200":
479+
description: Successful response
480+
423481
/cookies:
424482
get:
425483
tags:

packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamTextFormItem.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ export default function ParamTextFormItem({
3838
setParam({
3939
...param,
4040
value:
41-
param.in === "path" || param.in === "query"
41+
param.in === "path"
4242
? e.target.value.replace(/\s/g, "%20")
43-
: e.target.value,
43+
: param.in === "query"
44+
? encodeURIComponent(e.target.value)
45+
: e.target.value,
4446
})
4547
)
4648
}

0 commit comments

Comments
 (0)