[Mime] Fix boundary header
This commit is contained in:
parent
14b825b24f
commit
453078ff37
@ -91,7 +91,7 @@ abstract class AbstractMultipartPart extends AbstractPart
|
|||||||
private function getBoundary(): string
|
private function getBoundary(): string
|
||||||
{
|
{
|
||||||
if (null === $this->boundary) {
|
if (null === $this->boundary) {
|
||||||
$this->boundary = '_=_symfony_'.time().'_'.bin2hex(random_bytes(16)).'_=_';
|
$this->boundary = strtr(base64_encode(random_bytes(6)), '+/', '-_');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->boundary;
|
return $this->boundary;
|
||||||
|
@ -91,4 +91,16 @@ class FormDataPartTest extends TestCase
|
|||||||
$this->assertEquals($foo, $parts[0]->bodyToString());
|
$this->assertEquals($foo, $parts[0]->bodyToString());
|
||||||
$this->assertEquals($bar, $parts[1]->bodyToString());
|
$this->assertEquals($bar, $parts[1]->bodyToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testBoundaryContentTypeHeader()
|
||||||
|
{
|
||||||
|
$f = new FormDataPart([
|
||||||
|
'file' => new DataPart('data.csv', 'data.csv', 'text/csv'),
|
||||||
|
]);
|
||||||
|
$headers = $f->getPreparedHeaders()->toArray();
|
||||||
|
$this->assertRegExp(
|
||||||
|
'/^Content-Type: multipart\/form-data; boundary=[a-zA-Z0-9\-_]{8}$/',
|
||||||
|
$headers[0]
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user