-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
FormRequestServiceProvider
tries to copy non-JSON request as JSON
#42106
Comments
Can you give a clear way to reproduce this in a fresh Laravel app? |
|
I'll need a clear explanation of what actually breaks. There's still no bug here. Having |
I don't think there's a big issue here tbh. You're free to make a proposal through a PR if you want. Thanks |
It is a bug in combination with #42107, because this is one of the code lines which set However, and this are the real bugs, the copy-method
Luckily, |
Description:
Summary
During bootstrapping, the
FormRequestServiceProvider
makes a deep copy of theRequest
object. While doing so, anyRequest
is treated as if it contained JSON payload which leads to the side-effect thatjson_last_error
is set for non-JSON requests. As other parts of Laravel check forjson_last_error
being clear later on, this has undesired effects.Details
At some point during bootstrapping, the backtrace looks basically like this
and the
Request
object makes a deep copy of itself inIlluminate\Http\Request::createFrom()
.The problematic line is
$request->setJson($from->json())
and the invocation of$from->json()
. This getter method is not side-effect free.For non-JSON requests, this method calls
json_decode
on content which is not JSON. As a smaller cosmetic defect, it also modifies the original request$from
by setting$this->json
to an new, emptyParameterBag
.Proposed solution
Remove
$request->setJson($from->json())
fromIlluminate\Http\Request::createFrom()
.Calling this method is not necessary at all for making a deep copy. Everything which is needed is already copied by
$request->initialize(...)
some line earlier, especially the content of the request. If a JSON interpretation of the content is required later in the application, thenjson()
can (and will) still be called on the deep copy which leads to the exact same result. Bonus points:json_decode
for non-JSON requestsjson_get_last_error
Request
objectThe text was updated successfully, but these errors were encountered: