Skip to content

Commit 59c282e

Browse files
committed
Issue #3032620 by alexpott, dww: \Drupal\file\Plugin\rest\resource\FileUploadResource uses basename() when it needs to use the Drupal version
(cherry picked from commit e1ec253)
1 parent 4a092fa commit 59c282e

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

modules/file/src/Plugin/rest/resource/FileUploadResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ protected function validateAndParseContentDispositionHeader(Request $request) {
374374

375375
// Make sure only the filename component is returned. Path information is
376376
// stripped as per https://tools.ietf.org/html/rfc6266#section-4.3.
377-
return basename($filename);
377+
return $this->fileSystem->basename($filename);
378378
}
379379

380380
/**

modules/rest/tests/src/Functional/FileUploadResourceTestBase.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,13 @@ public function testFileUploadUnicodeFilename() {
373373

374374
$uri = Url::fromUri('base:' . static::$postUri);
375375

376-
$response = $this->fileRequest($uri, $this->testFileData, ['Content-Disposition' => 'file; filename="example-✓.txt"']);
376+
// It is important that the filename starts with a unicode character. See
377+
// https://bugs.php.net/bug.php?id=77239.
378+
$response = $this->fileRequest($uri, $this->testFileData, ['Content-Disposition' => 'file; filename="Èxample-✓.txt"']);
377379
$this->assertSame(201, $response->getStatusCode());
378-
$expected = $this->getExpectedNormalizedEntity(1, 'example-✓.txt', TRUE);
380+
$expected = $this->getExpectedNormalizedEntity(1, 'Èxample-✓.txt', TRUE);
379381
$this->assertResponseData($expected, $response);
380-
$this->assertSame($this->testFileData, file_get_contents('public://foobar/example-✓.txt'));
382+
$this->assertSame($this->testFileData, file_get_contents('public://foobar/Èxample-✓.txt'));
381383
}
382384

383385
/**

0 commit comments

Comments
 (0)