Skip to content

Commit

Permalink
[Mime] Fix boundary header
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Pédelagrabe authored and fabpot committed Mar 14, 2020
1 parent 14b825b commit 453078f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Mime/Part/AbstractMultipartPart.php
Expand Up @@ -91,7 +91,7 @@ public function asDebugString(): string
private function getBoundary(): string
{
if (null === $this->boundary) {
$this->boundary = '_=_symfony_'.time().'_'.bin2hex(random_bytes(16)).'_=_';
$this->boundary = strtr(base64_encode(random_bytes(6)), '+/', '-_');
}

return $this->boundary;
Expand Down
Expand Up @@ -91,4 +91,16 @@ public function testContentLineLength()
$this->assertEquals($foo, $parts[0]->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]
);
}
}

0 comments on commit 453078f

Please sign in to comment.