Skip to content

Commit f4587d4

Browse files
Request path parameters should be encoded
1 parent 273a9d2 commit f4587d4

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Route.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { IncomingHttpHeaders } from 'http';
77
import { DocumentNode, parse, print, getOperationAST } from 'graphql';
88
import { AxiosTransformer, AxiosInstance, AxiosRequestConfig } from 'axios';
99
import * as express from 'express';
10+
import { encode } from 'punycode';
1011

1112
const PATH_VARIABLES_REGEX = /:([A-Za-z]+)/g
1213

@@ -268,14 +269,15 @@ export default class Route implements IMountableItem {
268269
//
269270
// This method will iterate through all variables, check their definition type from the spec
270271
// and typecast them
271-
private typecastVariables(variables: { [key: string]: string }): { [key: string]: any } {
272+
private typecastVariables(variables: { [key: string]: string }, encoder?: Function): { [key: string]: any } {
272273
const parsedVariables: { [key: string]: any } = {};
273274

274275
Object.entries(variables).forEach(
275276
([variableName, value]) => {
276277
const variableDefinition = this.operationVariables[variableName];
278+
const typecastValue = typecastVariable(value, variableDefinition);
277279

278-
parsedVariables[variableName] = typecastVariable(value, variableDefinition);
280+
parsedVariables[variableName] = encoder ? encode(typecastValue) : typecastValue;
279281
}
280282
);
281283

@@ -287,7 +289,7 @@ export default class Route implements IMountableItem {
287289
const { query, params, body } = req;
288290

289291
const parsedQueryVariables = this.typecastVariables(query);
290-
const parsedPathVariables = this.typecastVariables(params);
292+
const parsedPathVariables = this.typecastVariables(params, encodeURI);
291293

292294
const providedVariables = { ...parsedQueryVariables, ...parsedPathVariables, ...body };
293295

0 commit comments

Comments
 (0)