-
-
Notifications
You must be signed in to change notification settings - Fork 796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request Template - Post JSON Body With Single Quote #187
Comments
Hi @dizard2001 thanks for reporting this. It looks like a bug with the velocity parser helper functions. I believe it is trying to call this function but for some reason |
@dherault sorry for the late reply. The type of the output of $util.escapeJavascript(data) is a String. Additionally the format of the return after that call in my case is: When I have more time I can dig into the issue a bit more. |
Hi guys, it is still the case in v3.11.0 ? Thanks |
ping :) v3.13.3 |
serverless-offline: 3.8.3
serverless: 1.4.0
When posting a Json object that contains a single quote in a property value, I was getting a bad request from the api-gateway. After researching I adjusted my code as per http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html to use $util.escapeJavaScript(data).replaceAll("\'","'"). I've used this and it's successful when the lambda function is deployed into AWS, but when running as serverless offline I get the following error:
Serverless: POST /feedback (λ: feedback)
Serverless: The first request might take a few extra seconds
Serverless:
Serverless: Error while parsing template "application/json" for feedback
[ 'Error: this.replace is not a function on $util.escapeJavaScript($input.json('$')).replaceAll("\\'","'") at L/N 2:11',
'at Velocity.utils.mixin.getPropMethod (/Users/danderson/src/project-task-board-api/node_modules/serverless-offline/node_modules/velocityjs/src/compile/references.js:297:19)',
...
My serverless.yml:
feedback: handler: functions/feedback/post.handler events: - http: cors: true path: feedback method: post integration: lambda request: template: application/json: > { "body": "$util.escapeJavaScript($input.json('$')).replaceAll("\\'","'")", "headers": { #foreach($param in $input.params().header.keySet()) "$param": "$util.escapeJavaScript($input.params().header.get($param))" #if($foreach.hasNext),#end #end } }
I tried combing through both closed and open issues related to this and came across #50. If I'm understanding it correctly, the escape javascript call returns an object instead of a string(as in AWS) and so the function isn't defined. As per the recommendation of applying a JSON.stringify to the output, this is resulting in just an empty string. Any insight would be appreciated.
The text was updated successfully, but these errors were encountered: