bug #37581 [Mime] Fix compat with HTTP requests (fabpot)

This PR was merged into the 4.4 branch.

Discussion
----------

[Mime] Fix compat with HTTP requests

| Q             | A
| ------------- | ---
| Branch?       | 4.4 <!-- see below -->
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | Fix #37500, Fix #36738, Fix #35443
| License       | MIT
| Doc PR        | n/a

Commits
-------

52e7d7cf17 [Mime] Fix compat with HTTP requests
This commit is contained in:
Fabien Potencier 2020-07-15 14:00:31 +02:00
commit f617380af5
2 changed files with 3 additions and 2 deletions

View File

@ -158,7 +158,8 @@ final class ParameterizedHeader extends UnstructuredHeader
*/
private function getEndOfParameterValue(string $value, bool $encoded = false, bool $firstLine = false): string
{
if (!preg_match('/^'.self::TOKEN_REGEX.'$/D', $value)) {
$forceHttpQuoting = 'content-disposition' === strtolower($this->getName()) && 'form-data' === $this->getValue();
if ($forceHttpQuoting || !preg_match('/^'.self::TOKEN_REGEX.'$/D', $value)) {
$value = '"'.$value.'"';
}
$prepend = '=';

View File

@ -129,7 +129,7 @@ class TextPart extends AbstractPart
if ($this->charset) {
$headers->setHeaderParameter('Content-Type', 'charset', $this->charset);
}
if ($this->name) {
if ($this->name && 'form-data' !== $this->disposition) {
$headers->setHeaderParameter('Content-Type', 'name', $this->name);
}
$headers->setHeaderBody('Text', 'Content-Transfer-Encoding', $this->encoding);