File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,6 +20,17 @@ test('getPathWithQueryStringParams: 1 param', () => {
2020 expect ( pathWithQueryStringParams ) . toEqual ( '/foo/bar?bizz=bazz' )
2121} )
2222
23+ test ( 'getPathWithQueryStringParams: to be url-encoded param' , ( ) => {
24+ const event = {
25+ path : '/foo/bar' ,
26+ queryStringParameters : {
27+ 'redirect_uri' : 'http://lvh.me:3000/cb'
28+ }
29+ }
30+ const pathWithQueryStringParams = awsServerlessExpress . getPathWithQueryStringParams ( event )
31+ expect ( pathWithQueryStringParams ) . toEqual ( '/foo/bar?redirect_uri=http%3A%2F%2Flvh.me%3A3000%2Fcb' )
32+ } )
33+
2334test ( 'getPathWithQueryStringParams: 2 params' , ( ) => {
2435 const event = {
2536 path : '/foo/bar' ,
Original file line number Diff line number Diff line change 1414 */
1515'use strict'
1616const http = require ( 'http' )
17+ const url = require ( 'url' )
1718const binarycase = require ( 'binary-case' )
1819
1920function getPathWithQueryStringParams ( event ) {
20- const queryStringKeys = Object . keys ( event . queryStringParameters || { } )
21-
22- if ( queryStringKeys . length === 0 ) return event . path
23-
24- const queryStringParams = queryStringKeys . map ( queryStringKey => `${ queryStringKey } =${ encodeURIComponent ( event . queryStringParameters [ queryStringKey ] ) } ` ) . join ( '&' )
25-
26- return `${ event . path } ?${ queryStringParams } `
21+ return url . format ( { pathname : event . path , query : event . queryStringParameters } )
2722}
2823
2924function mapApiGatewayEventToHttpRequest ( event , context , socketPath ) {
You can’t perform that action at this time.
0 commit comments