Skip to content

Commit 68f3709

Browse files
fix: add charset as utf-8 (#9)
1 parent f89d458 commit 68f3709

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

.DS_Store

6 KB
Binary file not shown.

src/request.spec.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,19 @@ describe('Request object version 1.0', () => {
2626
'c[]': 'lastName',
2727
'd[1]': '1',
2828
'd[0]': '0',
29-
'shoe[color]': 'yellow'
29+
'shoe[color]': 'yellow',
30+
email: 'test%2Buser%40gmail.com',
31+
math: '1%2B2'
3032
},
3133
multiValueQueryStringParameters: {
3234
a: ['1'],
3335
b: ['1', '2'],
3436
'c[]': ['-firstName', 'lastName'],
3537
'd[1]': ['1'],
3638
'd[0]': ['0'],
37-
'shoe[color]': ['yellow']
39+
'shoe[color]': ['yellow'],
40+
email: ['test%2Buser%40gmail.com'],
41+
math: ['1%2B2', '4%2B5']
3842
},
3943
stageVariables: {},
4044
requestContext: {},
@@ -47,6 +51,7 @@ describe('Request object version 1.0', () => {
4751

4852
expect(request.query.a).toBe('1')
4953
expect(request.query.shoe.color).toBe('yellow')
54+
expect(request.query.email).toBe('[email protected]')
5055
})
5156

5257
it('should read all values of query parameter with multiple values', () => {
@@ -55,6 +60,7 @@ describe('Request object version 1.0', () => {
5560
expect(request.query.b).toEqual(['1', '2'])
5661
expect(request.query.c).toEqual(['-firstName', 'lastName'])
5762
expect(request.query.d).toEqual(['0', '1'])
63+
expect(request.query.math).toEqual(['1+2', '4+5'])
5864
})
5965

6066
it('should read header', () => {
@@ -193,7 +199,8 @@ describe('Request object version 2.0', () => {
193199
version: '2.0',
194200
routeKey: '$default',
195201
rawPath: '/my/path',
196-
rawQueryString: 'a=1&b=1&b=2&c[]=-firstName&c[]=lastName&d[1]=1&d[0]=0&shoe[color]=yellow&',
202+
rawQueryString:
203+
'a=1&b=1&b=2&c[]=-firstName&c[]=lastName&d[1]=1&d[0]=0&shoe[color]=yellow&email=test%2Buser%40gmail.com&math=1%2B2&&math=4%2B5&',
197204
cookies: ['cookie1', 'cookie2'],
198205
headers: {
199206
'Content-Type': 'application/json',
@@ -202,11 +209,13 @@ describe('Request object version 2.0', () => {
202209
},
203210
queryStringParameters: {
204211
a: '1',
205-
b: '1,2',
206-
'c[]': '-firstName,lastName',
212+
b: '2',
213+
'c[]': 'lastName',
207214
'd[1]': '1',
208215
'd[0]': '0',
209-
'shoe[color]': 'yellow'
216+
'shoe[color]': 'yellow',
217+
email: 'test%2Buser%40gmail.com',
218+
math: '1%2B2'
210219
},
211220
requestContext: {
212221
accountId: '123456789012',
@@ -264,6 +273,7 @@ describe('Request object version 2.0', () => {
264273

265274
expect(request.query.a).toBe('1')
266275
expect(request.query.shoe.color).toBe('yellow')
276+
expect(request.query.email).toBe('[email protected]')
267277
})
268278

269279
it('should read all values of query parameter with multiple values', () => {
@@ -272,6 +282,7 @@ describe('Request object version 2.0', () => {
272282
expect(request.query.b).toEqual(['1', '2'])
273283
expect(request.query.c).toEqual(['-firstName', 'lastName'])
274284
expect(request.query.d).toEqual(['0', '1'])
285+
expect(request.query.math).toEqual(['1+2', '4+5'])
275286
})
276287

277288
it('should read header', () => {

src/request.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ export class Request extends Readable {
7474
}
7575
}
7676

77-
this.query = parse(queryParamsToStringify(event.multiValueQueryStringParameters), {}) as {
77+
this.query = parse(queryParamsToStringify(event.multiValueQueryStringParameters), {
78+
charset: 'utf-8'
79+
}) as {
7880
[name: string]: string | string[]
7981
}
8082

@@ -289,7 +291,9 @@ export class RequestV2 extends Readable {
289291
this.hostname = this.headers.host || ''
290292
this.method = event.requestContext.http.method
291293

292-
this.query = parse(event.rawQueryString) as { [name: string]: string }
294+
this.query = parse(event.rawQueryString, {
295+
charset: 'utf-8'
296+
}) as { [name: string]: string }
293297

294298
this.path = event.rawPath || ''
295299
this.url = event.rawPath

0 commit comments

Comments
 (0)