Skip to content
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

jsonDecode is assuming that everything is an array #116

Open
garak opened this issue Jul 28, 2022 · 7 comments · May be fixed by #117
Open

jsonDecode is assuming that everything is an array #116

garak opened this issue Jul 28, 2022 · 7 comments · May be fixed by #117

Comments

@garak
Copy link

garak commented Jul 28, 2022

jsonDecode method assumes that every value decoded from a JSON string is an array.
This is a wrong assumption since the value can also be a string, a boolean, or null. See also PHP Manual

@christeredvartsen
Copy link
Member

Could you provide an example where this piece of code breaks because of this assumption?

@garak
Copy link
Author

garak commented Aug 1, 2022

For example, when the JSON string passed is "OK"

@christeredvartsen
Copy link
Member

Do you have a feature file that I can try out so I can see the example with some context?

@garak
Copy link
Author

garak commented Aug 1, 2022

Not at the moment. Anyway, you can simply have an endpoint returning "OK" and assertion that the JSON response is that string

@christeredvartsen
Copy link
Member

For values other than arrays you could simply use Then the response body is: <PyStringNode> instead though:

https://behat-api-extension.readthedocs.io/en/latest/guide/verify-server-response.html#then-the-response-body-is-pystringnode

@garak
Copy link
Author

garak commented Aug 2, 2022

That would prevent me from validating that the content is a proper JSON string

@christeredvartsen
Copy link
Member

You could probably do that quite easy with a custom check.

I don't personally see the benefit of fixing the existing code for this, but if you want to provide a PR I would most likely merge it.

@garak garak linked a pull request Aug 11, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants