diff --git a/composer.json b/composer.json index b559583738bd..747b37a0f6c3 100644 --- a/composer.json +++ b/composer.json @@ -47,7 +47,7 @@ "symfony/console": "^7.0.3", "symfony/error-handler": "^7.0.3", "symfony/finder": "^7.0.3", - "symfony/http-foundation": "^7.0.3", + "symfony/http-foundation": "^7.2.0", "symfony/http-kernel": "^7.0.3", "symfony/mailer": "^7.0.3", "symfony/mime": "^7.0.3", diff --git a/src/Illuminate/Http/UploadedFile.php b/src/Illuminate/Http/UploadedFile.php index bdc4e62e1c0e..5c3113021fc5 100644 --- a/src/Illuminate/Http/UploadedFile.php +++ b/src/Illuminate/Http/UploadedFile.php @@ -133,7 +133,7 @@ public static function createFromBase(SymfonyUploadedFile $file, $test = false) { return $file instanceof static ? $file : new static( $file->getPathname(), - $file->getClientOriginalName(), + $file->getClientOriginalPath(), $file->getClientMimeType(), $file->getError(), $test diff --git a/tests/Http/HttpUploadedFileTest.php b/tests/Http/HttpUploadedFileTest.php index 35850eb48729..7d12b7b5a4ac 100644 --- a/tests/Http/HttpUploadedFileTest.php +++ b/tests/Http/HttpUploadedFileTest.php @@ -4,6 +4,7 @@ use Illuminate\Http\UploadedFile; use PHPUnit\Framework\TestCase; +use Symfony\Component\HttpFoundation\File\UploadedFile as SymfonyUploadedFile; class HttpUploadedFileTest extends TestCase { @@ -19,4 +20,49 @@ public function testUploadedFileCanRetrieveContentsFromTextFile() $this->assertSame('This is a story about something that happened long ago when your grandfather was a child.', trim($file->get())); } + + public function testUploadedFileInRequestContainsOriginalPathAndName() + { + $symfonyFile = new SymfonyUploadedFile(__FILE__, ''); + $this->assertSame('', $symfonyFile->getClientOriginalName()); + $this->assertSame('', $symfonyFile->getClientOriginalPath()); + $file = UploadedFile::createFromBase($symfonyFile); + $this->assertSame('', $file->getClientOriginalName()); + $this->assertSame('', $file->getClientOriginalPath()); + + $symfonyFile = new SymfonyUploadedFile(__FILE__, 'test.txt'); + $this->assertSame('test.txt', $symfonyFile->getClientOriginalName()); + $this->assertSame('test.txt', $symfonyFile->getClientOriginalPath()); + $file = UploadedFile::createFromBase($symfonyFile); + $this->assertSame('test.txt', $file->getClientOriginalName()); + $this->assertSame('test.txt', $file->getClientOriginalPath()); + + $symfonyFile = new SymfonyUploadedFile(__FILE__, '/test.txt'); + $this->assertSame('test.txt', $symfonyFile->getClientOriginalName()); + $this->assertSame('/test.txt', $symfonyFile->getClientOriginalPath()); + $file = UploadedFile::createFromBase($symfonyFile); + $this->assertSame('test.txt', $file->getClientOriginalName()); + $this->assertSame('/test.txt', $file->getClientOriginalPath()); + + $symfonyFile = new SymfonyUploadedFile(__FILE__, '/foo/bar/test.txt'); + $this->assertSame('test.txt', $symfonyFile->getClientOriginalName()); + $this->assertSame('/foo/bar/test.txt', $symfonyFile->getClientOriginalPath()); + $file = UploadedFile::createFromBase($symfonyFile); + $this->assertSame('test.txt', $file->getClientOriginalName()); + $this->assertSame('/foo/bar/test.txt', $file->getClientOriginalPath()); + + $symfonyFile = new SymfonyUploadedFile(__FILE__, '/foo/bar/test.txt'); + $this->assertSame('test.txt', $symfonyFile->getClientOriginalName()); + $this->assertSame('/foo/bar/test.txt', $symfonyFile->getClientOriginalPath()); + $file = UploadedFile::createFromBase($symfonyFile); + $this->assertSame('test.txt', $file->getClientOriginalName()); + $this->assertSame('/foo/bar/test.txt', $file->getClientOriginalPath()); + + $symfonyFile = new SymfonyUploadedFile(__FILE__, 'file:\\foo\\test.txt'); + $this->assertSame('test.txt', $symfonyFile->getClientOriginalName()); + $this->assertSame('file:/foo/test.txt', $symfonyFile->getClientOriginalPath()); + $file = UploadedFile::createFromBase($symfonyFile); + $this->assertSame('test.txt', $file->getClientOriginalName()); + $this->assertSame('file:/foo/test.txt', $file->getClientOriginalPath()); + } }