Skip to content
Myr

fix(aws-lambda): Update handler.ts getQueryString (#2782)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Updated the getQueryString function to handle the case when both queryStringParameters and multiValueQueryStringParameters properties exists.

authored by Tshepo Mgaga · committed by GitHub · parent d6fa9d4 · Browse files · 1 file+16 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+16 added−5 removed

  • other:+16 added−5 removed

1 file+16 added−5 removed

modified:src/adapter/aws-lambda/handler.ts+16 added-5 removed
407 unmodified lines
408 }409410 protected getQueryString(event: ALBProxyEvent): string {411 // In the case of ALB Integration either queryStringParameters or multiValueQueryStringParameters can be present not both412 /* 413 In other cases like when using the serverless framework, the event object does contain both queryStringParameters and multiValueQueryStringParameters:414 Below is an example event object for this URL: /payment/b8c55e69?select=amount&select=currency415 {416 ...417 queryStringParameters: { select: 'currency' },418 multiValueQueryStringParameters: { select: [ 'amount', 'currency' ] },419 }420 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.421 A simple fix would be to invert the if statement and check the multiValueQueryStringParameters first.422 */412 if (event.queryStringParameters) {413 return Object.entries(event.queryStringParameters || {})423 if (event.multiValueQueryStringParameters) {424 return Object.entries(event.multiValueQueryStringParameters || {})425 .filter(([, value]) => value)415 .map(([key, value]) => `${key}=${value}`)426 .map(([key, value]) => `${key}=${value.join(`&${key}=`)}`)427 .join('&')428 } else {418 return Object.entries(event.multiValueQueryStringParameters || {})429 return Object.entries(event.queryStringParameters || {})430 .filter(([, value]) => value)420 .map(([key, value]) => `${key}=${value.join(`&${key}=`)}`)431 .map(([key, value]) => `${key}=${value}`)432 .join('&')433 }434 }435
59 unmodified lines