Skip to content

Commit

Permalink
fix(aws-lambda): Update handler.ts getQueryString (#2782)
Browse files Browse the repository at this point in the history
Updated the getQueryString function to handle the case when both queryStringParameters and multiValueQueryStringParameters properties exists.
  • Loading branch information
qualipsolutions authored May 27, 2024
1 parent d6fa9d4 commit dfbc6c4
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/adapter/aws-lambda/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,15 +409,26 @@ class ALBProcessor extends EventProcessor<ALBProxyEvent> {

protected getQueryString(event: ALBProxyEvent): string {
// In the case of ALB Integration either queryStringParameters or multiValueQueryStringParameters can be present not both
if (event.queryStringParameters) {
return Object.entries(event.queryStringParameters || {})
/*
In other cases like when using the serverless framework, the event object does contain both queryStringParameters and multiValueQueryStringParameters:
Below is an example event object for this URL: /payment/b8c55e69?select=amount&select=currency
{
...
queryStringParameters: { select: 'currency' },
multiValueQueryStringParameters: { select: [ 'amount', 'currency' ] },
}
The expected results is for select to be an array with two items. However the pre-fix code is only returning one item ('currency') in the array.
A simple fix would be to invert the if statement and check the multiValueQueryStringParameters first.
*/
if (event.multiValueQueryStringParameters) {
return Object.entries(event.multiValueQueryStringParameters || {})
.filter(([, value]) => value)
.map(([key, value]) => `${key}=${value}`)
.map(([key, value]) => `${key}=${value.join(`&${key}=`)}`)
.join('&')
} else {
return Object.entries(event.multiValueQueryStringParameters || {})
return Object.entries(event.queryStringParameters || {})
.filter(([, value]) => value)
.map(([key, value]) => `${key}=${value.join(`&${key}=`)}`)
.map(([key, value]) => `${key}=${value}`)
.join('&')
}
}
Expand Down

0 comments on commit dfbc6c4

Please sign in to comment.