Skip to content

Commit b6cb0f2

Browse files
authored
Merge pull request #279 from WhispRnD/fix_proxy_single_quotes
Fix serialization errors in lambda_proxy template when using single quotes in payload
2 parents effcfd1 + b43dd8d commit b6cb0f2

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/deploy/events/apiGateway/methods.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ const LAMBDA_PROXY_REQUEST_TEMPLATE = `
6969
#set( $map = $context.authorizer )
7070
"authorizer": $loop,
7171
},
72-
"body": "$util.escapeJavaScript("$body")",
72+
"body": "$util.escapeJavaScript("$body").replaceAll("\\\\'", "'")",
7373
"isBase64Encoded": false
7474
}
7575
#end
7676
{
77-
"input": "$util.escapeJavaScript("$smInput")",
77+
"input": "$util.escapeJavaScript("$smInput").replaceAll("\\\\'", "'")",
7878
"name":"$context.requestId",
7979
"stateMachineArn":"\${StateMachineArn}"
8080
}`;

lib/deploy/events/apiGateway/methods.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,20 @@ describe('#methods()', () => {
284284
});
285285
});
286286

287+
describe('#getLambdaProxyRequestTemplates()', () => {
288+
it('application/json proxy template should not have escaped single quotes', () => {
289+
const lambdaProxyRequestTemplate = serverlessStepFunctions
290+
.getLambdaProxyRequestTemplates('stateMachine', undefined);
291+
292+
// Using negative lookahead, look for escapeJavaScript calls without the
293+
// required stripping of escaped single quotes after
294+
const escapeJavascriptPattern = /\$util.escapeJavaScript\("\$\w+"\)/;
295+
const unescapeSingleQuotesPattern = /\.replaceAll\("\\\\'", *"'"\)/;
296+
const regExp = new RegExp(`${escapeJavascriptPattern.source}(?!${unescapeSingleQuotesPattern.source})`);
297+
expect(lambdaProxyRequestTemplate['application/json']['Fn::Sub'][0]).not.to.match(regExp);
298+
});
299+
});
300+
287301
describe('#getMethodResponses()', () => {
288302
it('should return a corresponding methodResponses resource', () => {
289303
expect(serverlessStepFunctions.getMethodResponses().Properties)

0 commit comments

Comments
 (0)