-
Notifications
You must be signed in to change notification settings - Fork 46
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
String Provider State Params Serialised As Numbers #263
Comments
👋 Hi! The 'smartbear-supported' label has just been added to this issue, which will create an internal tracking ticket in PactFlow's Jira (PACT-937). We will use this to prioritise and assign a team member to this task. All activity will be public on this ticket. For now, sit tight and we'll update this ticket once we have more information on the next steps. |
If you are using the function pactffi_given_with_param(interaction, "state with param", name: "issue", value: "\"449\"") |
How come we only have to do that for numbers? Other strings that get passed in don't have quotes around them and thus would be invalid JSON. I'd have to check what Boolean values do but could have a similar problem. What happens if a regular string has quotes around it? Would those be stripped or would they cause parse errors? That seems pretty unexpected. |
If it can't parse it as JSON, it falls back to using the raw string. The problem here is it can parse it as JSON, which is needed in case you actually want to pass numbers and booleans in. |
So if a user passes That feels like a bit of a foot gun. Does that mean all FFI consumers need to escape all possible JSON values from user input, just in case it happens to parse as valid JSON when that wasn't intended? That would be a non-trivial task to implement everywhere. What if they pass something like |
This is not meant to be the format the user provides, that should be an idiomatic value for the language being used. For instance, with Ruby, Python or Groovy the user would be able to pass a map of values, and it should be converted to JSON behind the scenes. |
I'd question if this is really closed as completed. I think it's clear that users could get really weird unexpected behaviour with this. |
It would be best to prove or disprove this with tests, and then we have something to work with, as well as some documentation for users. As to Ron's comment about using json and a commit to update the docstring for usage here I've implemented that in your issue repro over in pact-net (thank you!), and using the documented suggestion by Ron (parsing as json) works as per your test case. Edge cases are to be expected but happy to unearth them. |
See: pact-foundation/pact-net#449
If a provider state param just happens to contain only numbers then it's serialised to the pact file as a number instead of a string.
You'd expect the pact file to contain:
but it contains
The text was updated successfully, but these errors were encountered: