Repository navigation
Conversation
A file input named `documents[]` or `profile[avatar]` reached the
application under the flat key `documents[]`, and two parts with the
same name kept only the last file, so `$request->file('documents')`
was null. File names are now parsed with parse_str, like the fields.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What's wrong
Since #261 a multipart body reaches the application, but a file input with an array or nested name does not.
parseMultipartBody()stores each file under its raw part name (src/Drivers/LaravelHttpServer.php#L506), and the docblock above it says so (#L479-L481): "Two parts with the same name keep the last file, and a nested name such asfiles[avatar]stays flat where PHP would nest it."So with
<input type="file" name="documents[]">× 2:array_keys($request->allFiles())["documents"]["documents[]"]$request->file('documents')[UploadedFile, UploadedFile]null$request->file('profile.avatar')forname="profile[avatar]"UploadedFilenullAny app that validates
documents.*orprofile.avatargets a 422 in a browser test even though the upload works in production. Text fields already nest correctly, because they go throughparse_str.Reproducing it
Without a browser, against v5.1.2:
End to end, in a fresh Laravel 13.36 app with v5.1.2 (PHP 8.4.25, Playwright 1.63.0, macOS):
The fix
File parts are collected in a list, and their names are run through
parse_strwith the list index as the value (documents[]=0&documents[]=1&profile[avatar]=2). The indexes are then swapped for the uploads. The nesting comes from the same function that already handles the text fields, so it matches$_FILES, including[]appends.removeUploads()now walks the nested array.Tests
The new test in
tests/Browser/Webpage/UploadTest.php(twodocuments[]inputs plus oneprofile[avatar]) fails on current5.xand passes with this change. The existing upload and attach tests still pass. pint, rector, phpstan and type coverage (100%) are clean.Related
mb_ltrim()corrupts binary bytes. Both fixes are needed before a browser test can upload a real image or PDF throughfiles[]. The two PRs only touch neighbouring lines ofUploadTest.php, so any conflict should be trivial.attach#232 adds multi-fileattach(), which makesfiles[]the usual case.🤖 Generated with Claude Code