Skip to content

Commit

Permalink
bug #46535 [Mime] Check that the path is a file in the DataPart::from…
Browse files Browse the repository at this point in the history
…Path (wkania)

This PR was squashed before being merged into the 4.4 branch.

Discussion
----------

[Mime] Check that the path is a file in the DataPart::fromPath

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        |

The directory can also be readable. Fix to the [PR](#36304).

Found it while working on another fix related to this method.

Commits
-------

a807523 [Mime] Check that the path is a file in the DataPart::fromPath
  • Loading branch information
chalasr committed Jun 1, 2022
2 parents f96da6d + a807523 commit 03bccf1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Mime/Part/DataPart.php
Expand Up @@ -61,7 +61,7 @@ public static function fromPath(string $path, string $name = null, string $conte
$contentType = self::$mimeTypes->getMimeTypes($ext)[0] ?? 'application/octet-stream';
}

if (false === is_readable($path)) {
if (!is_file($path) || !is_readable($path)) {
throw new InvalidArgumentException(sprintf('Path "%s" is not readable.', $path));
}

Expand Down
7 changes: 7 additions & 0 deletions src/Symfony/Component/Mime/Tests/Part/DataPartTest.php
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Mime\Tests\Part;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Mime\Exception\InvalidArgumentException;
use Symfony\Component\Mime\Header\Headers;
use Symfony\Component\Mime\Header\IdentificationHeader;
use Symfony\Component\Mime\Header\ParameterizedHeader;
Expand Down Expand Up @@ -127,6 +128,12 @@ public function testFromPathWithMeta()
), $p->getPreparedHeaders());
}

public function testFromPathWithNotAFile()
{
$this->expectException(InvalidArgumentException::class);
DataPart::fromPath(__DIR__.'/../Fixtures/mimetypes/');
}

public function testHasContentId()
{
$p = new DataPart('content');
Expand Down

0 comments on commit 03bccf1

Please sign in to comment.