-
Notifications
You must be signed in to change notification settings - Fork 475
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
Fixed an issue where delimited string and primitive values in payload were not parsed properly by Lambda Test Tool. #1851
Conversation
2f53875
to
10af223
Compare
@@ -318,6 +318,12 @@ private static string DeterminePayload(LocalLambdaOptions localLambdaOptions, Co | |||
} | |||
} | |||
|
|||
// Enclose simple string payload in double quotes so that it's parsed properly by Lambda JSON serializer. | |||
if (!payload.StartsWith("{") && !payload.StartsWith("\"")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm worried the logic we added in Amazon.Lambda.Tools isn't great logic to duplicate. The problem with the Amazon.Lambda.Tools logic is what if you want to send a bool or an int. This logic automatically converts true
to "true"
or 100
to "100"
.
I wonder instead if we should attempt to parse the JSON using with System.Text.Json. If that parses with no problems then send as is. If it doesn't parse add surrounding quotes if it doesn't already start with quotes then use that value. We could retrofit Amazon.Lambda.Tools with the same logic. I wouldn't view that as a breaking change there and we would fix some scenarios that aren't working correct in Amazon.Lambda.Tools.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented fix. Please review.
10af223
to
2e8b04f
Compare
2e8b04f
to
69d7f0f
Compare
69d7f0f
to
04c3722
Compare
04c3722
to
bfaba21
Compare
… were not parsed properly by Lambda Test Tool.
bfaba21
to
bef150b
Compare
Issue #, if available: #1135
Description of changes:
Fixed an issue where delimited JSON string payload was not parsed properly by Lambda Test Tool. This PR ports the string handling from .NET Lambda CLI tooling. .NET CLI Extensions tooling per logic here delimits the raw string payload with
"
if it doesn't start with{
. JSON strings are enclosed in double quotes:Per testing with
dotnet lambda invoke-function
:dotnet lambda-test-tool-6.0 --no-ui --payload ""hello""
, payload should be parsed ashello
.dotnet lambda-test-tool-6.0 --no-ui --payload '"hello"'
, payload should be parsed as'hello'
.EDIT: Per discussion with @normj, the implementation in .NET Extensions for CLI would not handle primitive types and needs to be fixed (refer #1197). I have implemented changes as suggested in this PR. Would work on .NET Extensions CLI tooling as part of issue #1197.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.