Issue #3402981 by kim.pepper, larowlan, quietone: Filename property is not updated when a duplicate file is renamed In REST and JSON API file uploads

merge-requests/6419/head
Lee Rowlands 2024-01-31 17:59:53 +10:00
parent 89ec081a50
commit 501e1ed2fb
No known key found for this signature in database
GPG Key ID: 2B829A3DF9204DC4
4 changed files with 18 additions and 5 deletions

View File

@ -330,6 +330,12 @@ class FileUploadResource extends ResourceBase {
}
$file->setFileUri($file_uri);
// Update the filename with any changes as a result of security or renaming
// due to an existing file.
// @todo Remove this duplication by replacing with FileUploadHandler. See
// https://www.drupal.org/project/drupal/issues/3401734
$file->setFilename($this->fileSystem->basename($file->getFileUri()));
// Move the file to the correct location after validation. Use
// FileSystemInterface::EXISTS_ERROR as the file location has already been
// determined above in FileSystem::getDestinationFilename().

View File

@ -245,6 +245,13 @@ class TemporaryJsonapiFileFieldUploader {
}
$file->setFileUri($file_uri);
// Update the filename with any changes as a result of security or renaming
// due to an existing file.
// @todo Remove this duplication by replacing with FileUploadHandler. See
// https://www.drupal.org/project/drupal/issues/3401734
$file->setFilename($this->fileSystem->basename($file->getFileUri()));
// Move the file to the correct location after validation. Use
// FileSystemInterface::EXISTS_ERROR as the file location has already been
// determined above in FileSystem::getDestinationFilename().

View File

@ -249,7 +249,7 @@ class FileUploadTest extends ResourceTestBase {
// header with no 'file' prefix.
$response = $this->fileRequest($uri, $this->testFileData, ['Content-Disposition' => 'filename="example.txt"']);
$this->assertSame(201, $response->getStatusCode());
$expected = $this->getExpectedDocument(2, 'example_0.txt');
$expected = $this->getExpectedDocument(2, 'example_0.txt', TRUE);
$this->assertResponseData($expected, $response);
// Check the actual file data.
@ -340,7 +340,7 @@ class FileUploadTest extends ResourceTestBase {
'data' => [
0 => $this->getExpectedDocument(1, 'existing.txt', TRUE, TRUE)['data'],
1 => $this->getExpectedDocument(2, 'example.txt', TRUE, TRUE)['data'],
2 => $this->getExpectedDocument(3, 'example_0.txt', FALSE, TRUE)['data'],
2 => $this->getExpectedDocument(3, 'example_0.txt', TRUE, TRUE)['data'],
],
];
$this->assertResponseData($expected, $response);
@ -448,7 +448,7 @@ class FileUploadTest extends ResourceTestBase {
$this->assertSame(201, $response->getStatusCode());
// Loading expected normalized data for file 2, the duplicate file.
$expected = $this->getExpectedDocument(2, 'example_0.txt');
$expected = $this->getExpectedDocument(2, 'example_0.txt', TRUE);
$this->assertResponseData($expected, $response);
// Check the actual file data.

View File

@ -195,7 +195,7 @@ abstract class FileUploadResourceTestBase extends ResourceTestBase {
// header with no 'file' prefix.
$response = $this->fileRequest($uri, $this->testFileData, ['Content-Disposition' => 'filename="example.txt"']);
$this->assertSame(201, $response->getStatusCode());
$expected = $this->getExpectedNormalizedEntity(2, 'example_0.txt');
$expected = $this->getExpectedNormalizedEntity(2, 'example_0.txt', TRUE);
$this->assertResponseData($expected, $response);
// Check the actual file data.
@ -317,7 +317,7 @@ abstract class FileUploadResourceTestBase extends ResourceTestBase {
$this->assertSame(201, $response->getStatusCode());
// Loading expected normalized data for file 2, the duplicate file.
$expected = $this->getExpectedNormalizedEntity(2, 'example_0.txt');
$expected = $this->getExpectedNormalizedEntity(2, 'example_0.txt', TRUE);
$this->assertResponseData($expected, $response);
// Check the actual file data.