From a807523f57d4984ffbe48c01abd9dd6b8b677a30 Mon Sep 17 00:00:00 2001 From: Wojciech Kania Date: Tue, 31 May 2022 23:20:05 +0200 Subject: [PATCH] [Mime] Check that the path is a file in the DataPart::fromPath --- src/Symfony/Component/Mime/Part/DataPart.php | 2 +- src/Symfony/Component/Mime/Tests/Part/DataPartTest.php | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Mime/Part/DataPart.php b/src/Symfony/Component/Mime/Part/DataPart.php index 75bcb64a9a9cb..e80a83946ef2e 100644 --- a/src/Symfony/Component/Mime/Part/DataPart.php +++ b/src/Symfony/Component/Mime/Part/DataPart.php @@ -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)); } diff --git a/src/Symfony/Component/Mime/Tests/Part/DataPartTest.php b/src/Symfony/Component/Mime/Tests/Part/DataPartTest.php index d8a08a24303c2..4d5b692744327 100644 --- a/src/Symfony/Component/Mime/Tests/Part/DataPartTest.php +++ b/src/Symfony/Component/Mime/Tests/Part/DataPartTest.php @@ -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; @@ -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'); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy