Skip to content

Commit 4cf83c3

Browse files
committed
Pass path parameter through decodeURIComponent
1 parent 652f21f commit 4cf83c3

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/compileOperation.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export function compileOperation(
6464
const regexMatchIndex = getPathParamIndex(path, parameter.name);
6565

6666
nodes.push(
67-
builders.variableDeclaration('const', [
67+
builders.variableDeclaration('let', [
6868
builders.variableDeclarator(
6969
identifier,
7070
builders.callExpression(schemaFn, [
@@ -83,6 +83,29 @@ export function compileOperation(
8383
]),
8484
);
8585

86+
// Path parameters should be decoded
87+
nodes.push(
88+
builders.ifStatement(
89+
builders.binaryExpression(
90+
'==',
91+
builders.unaryExpression('typeof', identifier, true),
92+
builders.literal('string'),
93+
),
94+
builders.blockStatement([
95+
builders.expressionStatement(
96+
builders.assignmentExpression(
97+
'=',
98+
identifier,
99+
builders.callExpression(
100+
builders.identifier('decodeURIComponent'),
101+
[identifier],
102+
),
103+
),
104+
),
105+
]),
106+
),
107+
);
108+
86109
// Return an error if the parameter is invalid
87110
nodes.push(
88111
builders.ifStatement(

tests/gitbook.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,21 @@ test('POST orgs/apple/members/jony (null)', () => {
213213
},
214214
});
215215
});
216+
217+
test('GET spaces/space_iphone-doc/content/path/apps%2Fphone', () => {
218+
const result = validateRequest({
219+
path: '/spaces/space_iphone-doc/content/path/apps%2Fphone',
220+
method: 'get',
221+
headers: {
222+
'content-type': 'application/json',
223+
},
224+
query: {},
225+
});
226+
expect(result).toMatchObject({
227+
operationId: 'getPageByPath',
228+
params: {
229+
spaceId: 'space_iphone-doc',
230+
pagePath: 'apps/phone',
231+
},
232+
});
233+
});

0 commit comments

Comments
 (0)