Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
23 changes: 17 additions & 6 deletions src/request.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@ describe('Request object version 1.0', () => {
'c[]': 'lastName',
'd[1]': '1',
'd[0]': '0',
'shoe[color]': 'yellow'
'shoe[color]': 'yellow',
email: 'test%2Buser%40gmail.com',
math: '1%2B2'
},
multiValueQueryStringParameters: {
a: ['1'],
b: ['1', '2'],
'c[]': ['-firstName', 'lastName'],
'd[1]': ['1'],
'd[0]': ['0'],
'shoe[color]': ['yellow']
'shoe[color]': ['yellow'],
email: ['test%2Buser%40gmail.com'],
math: ['1%2B2', '4%2B5']
},
stageVariables: {},
requestContext: {},
Expand All @@ -47,6 +51,7 @@ describe('Request object version 1.0', () => {

expect(request.query.a).toBe('1')
expect(request.query.shoe.color).toBe('yellow')
expect(request.query.email).toBe('test+user@gmail.com')
})

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

it('should read header', () => {
Expand Down Expand Up @@ -193,7 +199,8 @@ describe('Request object version 2.0', () => {
version: '2.0',
routeKey: '$default',
rawPath: '/my/path',
rawQueryString: 'a=1&b=1&b=2&c[]=-firstName&c[]=lastName&d[1]=1&d[0]=0&shoe[color]=yellow&',
rawQueryString:
'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&',
cookies: ['cookie1', 'cookie2'],
headers: {
'Content-Type': 'application/json',
Expand All @@ -202,11 +209,13 @@ describe('Request object version 2.0', () => {
},
queryStringParameters: {
a: '1',
b: '1,2',
'c[]': '-firstName,lastName',
b: '2',
'c[]': 'lastName',
'd[1]': '1',
'd[0]': '0',
'shoe[color]': 'yellow'
'shoe[color]': 'yellow',
email: 'test%2Buser%40gmail.com',
math: '1%2B2'
},
requestContext: {
accountId: '123456789012',
Expand Down Expand Up @@ -264,6 +273,7 @@ describe('Request object version 2.0', () => {

expect(request.query.a).toBe('1')
expect(request.query.shoe.color).toBe('yellow')
expect(request.query.email).toBe('test+user@gmail.com')
})

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

it('should read header', () => {
Expand Down
8 changes: 6 additions & 2 deletions src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ export class Request extends Readable {
}
}

this.query = parse(queryParamsToStringify(event.multiValueQueryStringParameters), {}) as {
this.query = parse(queryParamsToStringify(event.multiValueQueryStringParameters), {
charset: 'utf-8'
}) as {
[name: string]: string | string[]
}

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

this.query = parse(event.rawQueryString) as { [name: string]: string }
this.query = parse(event.rawQueryString, {
charset: 'utf-8'
}) as { [name: string]: string }

this.path = event.rawPath || ''
this.url = event.rawPath
Expand Down