Skip to content
Myr

fix(aws-lambda): preserve empty query parameters (#5292)

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

AWS event maps distinguish an empty string from an absent value. Retain empty values in API Gateway v1 and ALB request URLs so presence checks and validators see the original input.

authored by Ersa Oktavian Ramadan · committed by GitHub · parent 0d86899 · Browse files · 2 files+41 added−2 removed
This commit

State

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

Diff stats

2 files+41 added−2 removed

  • tests:+39 added−0 removed
  • other:+2 added−2 removed

2 files+41 added−2 removed

modified:src/adapter/aws-lambda/handler.test.ts+39 added
235 unmodified lines
236 expect(url.searchParams.get('equals')).toBe('a=b=c')237 expect(url.searchParams.get('ampersand')).toBe('a&b&c')238 })239240 it('Should preserve empty query parameters for version 1.0', () => {241 const event: LambdaEvent = {242 ...baseV1Event,243 queryStringParameters: {244 empty: '',245 present: '0',246 omitted: undefined,247 },248 }249250 const request = getProcessor(event).createRequest(event)251252 expect(request.url).toBe(253 'https://id.execute-api.us-east-1.amazonaws.com/my/path?empty=&present=0'254 )255 })256257 it('Should preserve empty query parameters for ALB events', () => {258 const event: LambdaEvent = {259 httpMethod: 'GET',260 path: '/my/path',261 headers: { host: 'example.test' },262 body: null,263 isBase64Encoded: false,264 queryStringParameters: {265 empty: '',266 present: '0',267 omitted: undefined,268 },269 requestContext: {270 elb: { targetGroupArn: 'arn:aws:elasticloadbalancing:...' },271 },272 }273274 const request = getProcessor(event).createRequest(event)275276 expect(request.url).toBe('https://example.test/my/path?empty=&present=0')277 })278279 it('Should return valid Request object from version 1.0 API Gateway event', () => {280 const event: LambdaEvent = {281 ...baseV1Event,282 headers: {
396 unmodified lines
modified:src/adapter/aws-lambda/handler.ts+2 added-2 removed
463 unmodified lines
464 )465 .join('&')466 } else {467 return Object.entries(event.queryStringParameters || {})468 .filter(([, value]) => value)468 .filter(([, value]) => value !== undefined)469 .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value || '')}`)470 .join('&')471 }472 }
81 unmodified lines
554 .map(([key, value]) => `${key}=${value.join(`&${key}=`)}`)555 .join('&')556 } else {557 return Object.entries(event.queryStringParameters || {})558 .filter(([, value]) => value)558 .filter(([, value]) => value !== undefined)559 .map(([key, value]) => `${key}=${value}`)560 .join('&')561 }562 }
120 unmodified lines