Skip to content

Commit

Permalink
fix(aws-lambda): Fix query string handling for v1 (#3717)
Browse files Browse the repository at this point in the history
  • Loading branch information
Holi0317 authored Dec 3, 2024
1 parent 190e122 commit 4af04a6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/adapter/aws-lambda/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ describe('EventProcessor.createRequest', () => {
header1: ['value1'],
header2: ['value1', 'value2', 'value3'],
},
// This value doesn't match multi value's content.
// We want to assert handler is using the multi value's content when both are available.
queryStringParameters: {
parameter2: 'value',
},
Expand Down Expand Up @@ -96,7 +98,7 @@ describe('EventProcessor.createRequest', () => {

expect(request.method).toEqual('GET')
expect(request.url).toEqual(
'https://id.execute-api.us-east-1.amazonaws.com/my/path?parameter2=value'
'https://id.execute-api.us-east-1.amazonaws.com/my/path?parameter1=value1&parameter1=value2&parameter2=value'
)
expect(Object.fromEntries(request.headers)).toEqual({
'content-type': 'application/json',
Expand Down
16 changes: 12 additions & 4 deletions src/adapter/aws-lambda/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,18 @@ export class EventV1Processor extends EventProcessor<Exclude<LambdaEvent, APIGat
}

protected getQueryString(event: Exclude<LambdaEvent, APIGatewayProxyEventV2>): string {
return Object.entries(event.queryStringParameters || {})
.filter(([, value]) => value)
.map(([key, value]) => `${key}=${value}`)
.join('&')
// In the case of gateway Integration either queryStringParameters or multiValueQueryStringParameters can be present not both
if (event.multiValueQueryStringParameters) {
return Object.entries(event.multiValueQueryStringParameters || {})
.filter(([, value]) => value)
.map(([key, value]) => `${key}=${value.join(`&${key}=`)}`)
.join('&')
} else {
return Object.entries(event.queryStringParameters || {})
.filter(([, value]) => value)
.map(([key, value]) => `${key}=${value}`)
.join('&')
}
}

protected getCookies(
Expand Down

0 comments on commit 4af04a6

Please sign in to comment.