Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Prevent unnecessary json_decode() call with empty request body #63

Closed
@BreiteSeite

Description

Currently, if the content-type header contains application/json, the JsonStrategy always runs json_decode() even if there is no body to decode.

Currently, json errors are saved in a global state (json_get_last_error() and json_get_last_error_msg()). I think it would be better if zend-expressive plays nice and does not taint that global state unless necessary by skipping the unnecessary json_decode() call.

Code to reproduce the issue

(send a request with content-type application/json but no request-body while having the body-params middleware configured)

see \ZendTest\Expressive\Helper\BodyParams\JsonStrategyTest::testEmptyRequestBodyYieldsNullParsedBodyWithNoExceptionThrown()

Expected results

json_last_error() returns JSON_ERROR_NONE

Actual results

json_last_error() returns JSON_ERROR_SYNTAX

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions