Repository navigation
fix: worker mode shapes multipart fields and files as PHP does - #64
Merged
Merged
Conversation
$r['post'] had each field's name as a key exactly as sent: "tags[]" was a
key of its own, a second "tags[]" overwrote the first, "user[name]" was
never nested. Laravel saw neither tags nor user in any form with a file
input (those post multipart).
The shim now registers each field with php_register_variable_safe, as
main/rfc1867.c builds $_POST: [] appends, [x] nests, a repeated name keeps
its last value, . and space in a top-level name become _, at most
max_input_vars fields. Not through sapi_module.input_filter: ext/filter's
filter writes POST variables into the real $_POST and its filter_input()
store and returns 0, which in a worker (one never-ending request) would
grow and carry fields between requests. The over-limit warning goes to
stderr, not to an app error handler mid-loop.
examples/laravel-worker.php nests the files the same way, with one
parse_str() of the field names (user[avatar] reaches
$request->file('user.avatar'); only name and name[] worked before).
- e2e a_worker_s_post_fields_are_shaped_as_php_shapes_post: PHP itself is
the oracle (same body to a per-request server); a second request shows
nothing carries over and $_POST is never written. Fails on the old shim
with "tags[]":"b".
- laravel-smoke: tags[], user[name] and user[avatar] reach Laravel
(all three null before); Laravel 12 and a fresh 13.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
In worker mode,
$r['post']had each field's name as a key, exactly as sent:tags[]was a key of its own, and a secondtags[]overwrote the first;user[name]was never nested.Laravel saw neither
tagsnoruserin any form with a file input, which are the forms that post multipart. The new smoke probe showed[null, null, null]fortags,useranduser.avatar.The fix
php_register_variable_safe, the waymain/rfc1867.cbuilds$_POST:[]appends and[x]nests;.and space in a top-level name become_;max_input_varsfields.sapi_module.input_filter, unlike rfc1867. I found this while testing: ext/filter's filter writes POST variables into the real$_POSTand itsfilter_input()store, then returns 0. In a worker, which is one request that never ends, that would grow with every request and carry fields from one request into the next. The only thing skipped isfilter.default, which PHP has deprecated.max_input_varswarning goes to stderr. Raised insideaskr_handle_request(), an app's error handler would turn it into an exception in the middle of the worker loop.laravel-worker.phpnests the files the same way, with oneparse_str()of the field names.user[avatar]now reaches$request->file('user.avatar'); before, onlynameandname[]worked.Verification
a_worker_s_post_fields_are_shaped_as_php_shapes_postuses PHP itself as the oracle: the same body is sent to a per-request server, where PHP builds$_POST.A second request shows that nothing carries over, and that the worker's own
$_POSTis never written.It fails on the old shim:
tags[],user[name]anduser[avatar]reach Laravel. Passes on Laravel 12 and on a fresh Laravel 13.A worker script that read raw names (
$r['post']['tags[]']) now gets PHP's shape. That is in the CHANGELOG.