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

Improve request parsing with invalid json #2066

Merged
merged 1 commit into from Mar 18, 2017
Merged

Conversation

moritz-h
Copy link
Contributor

Slim throws a runtime exception if json Request sends "semi valid" json code.

Here you expect json parsing to be an object, array or null:
https://github.com/slimphp/Slim/blob/3.x/Slim/Http/Request.php#L1015

If i send invalid json everything is fine, because the result ist null. If i send "semi valid" json like "foobar"
the runtime exception gets triggered.
The Problem is that the php function json_decode (called here) decodes a little more than valid json as mentioned here:
http://php.net/manual/en/function.json-decode.php
So "foobar" gets decoded as string, which is not an object, array or null.

I think ether you should accept "semi valid" json as result like php does or you should handle it like invalid json (i think better). But a RuntimeException looks totally wrong here.

I don't know how this should be fixed. The pull request just has tests for what i would expect.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 97.258% when pulling 368f978 on moritz-h:3.x into 66ff172 on slimphp:3.x.

@akrabat akrabat changed the title Add tests for expected request parsing with invalid json Improve request parsing with invalid json Mar 18, 2017
@akrabat akrabat merged commit 368f978 into slimphp:3.x Mar 18, 2017
akrabat added a commit that referenced this pull request Mar 18, 2017
@akrabat
Copy link
Member

akrabat commented Mar 18, 2017

Thanks. I've also fixed the bug.

@akrabat akrabat added this to the 3.8.0 milestone Mar 18, 2017
akrabat added a commit that referenced this pull request Mar 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants