Description
Symfony version(s) affected
6.4
Description
When you have retrieved a multipart form that has a type="file" and do not not send a file back when submitting the form the code fails at
https://github.com/symfony/symfony/blob/6.4/src/Symfony/Component/Mime/Part/TextPart.php#L149
How to reproduce
I am sorry that I did not write PHP code to reproduce nor did I figure out your unit test framework to submit a unit test. Please forgive me and note that I have been a long-time sponsor of the project :)
Note that I am using this through several layers of abstraction - Guzzle, and my own abstration that I built on top of that - so I don't really know how to exercise mime
directly to cause this, but submitting the following form that should reproduce the problem is as follows:
<form method="post" enctype="multipart/form-data">
<textarea name="text" cols="40" rows="10">
<input type="file" name="picture">
<input type="submit" value="Submit">
</form>
Retrieve the form or set up the form, set text
and ignore picture
, then submit the form (or perhaps just tell mime
to serialize the form in preparation for submission) - TextPart.php fails in line 149.
I wish I knew more about how my stack works top to bottom so I could give you a cool unit test - but alas this is the best I can do. Thanks for all you do.
Possible Solution
I have a copy of the code and was able to bypass the problem with the following quite imperfect workaround in the case where the file path is null.
This is not at all my recommended fix - it was just enough of a fix for my extremely limited use case that shows that (a) there is a series of calls that can lead to the the body path being null and (b) if you handle null things work better. I tried to trace the code upwards to make a smarter fix - but it was a morass of generators and magic yields that was difficult for me to lock down. I wish I could have yielded null
or something other than a blank string - but that worked well enough for me for now.
Additional Context
Thanks in advance - love the work your are doing to bring the PHP framework world together. The fewer dependencies we have and the more professionally maintained those dependencies are - the better life is in PHP world.
Happy to be a long-time sponsor of this project. -- Chuck
P.S. Don't judge me too much putting the vendor folder in github :) You have no idea how scary it is to type composer update
at the moment that my adopters are installing my software. As painful as my approach is, I know what they are running and know exactly what version of every dependency they are running. I can extensively test exactly one set of dependency versions than then hand it to my adopters who just do a git pull
:) And it also lets me patch around a bug in a dependency and move my adopting community forward.