Skip to content

Commit

Permalink
SA-CORE-2019-010 by larowlan, greggles, mlhess, kim.pepper, alexpott,…
Browse files Browse the repository at this point in the history
… dww, xjm, David_Rothstein
  • Loading branch information
larowlan committed Dec 18, 2019
1 parent 9148611 commit c94aa7f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/file/file.module
Expand Up @@ -992,7 +992,7 @@ function _file_save_upload_single(\SplFileInfo $file_info, $form_field_name, $va
$values = [
'uid' => $user->id(),
'status' => 0,
'filename' => $file_info->getClientOriginalName(),
'filename' => trim($file_info->getClientOriginalName(), '.'),
'uri' => $file_info->getRealPath(),
'filesize' => $file_info->getSize(),
];
Expand Down
17 changes: 17 additions & 0 deletions modules/file/tests/src/Functional/FileManagedFileElementTest.php
Expand Up @@ -2,6 +2,8 @@

namespace Drupal\Tests\file\Functional;

use Drupal\file\Entity\File;

/**
* Tests the 'managed_file' element type.
*
Expand Down Expand Up @@ -156,6 +158,21 @@ public function testManagedFileRemoved() {
$this->assertRaw('The file referenced by the Managed <em>file &amp; butter</em> field does not exist.');
}

/**
* Tests file names have leading . removed.
*/
public function testFileNameTrim() {
file_put_contents('public://.leading-period.txt', $this->randomString(32));
$last_fid_prior = $this->getLastFileId();
$this->drupalPostForm('file/test/0/0/0', [
'files[file]' => \Drupal::service('file_system')->realpath('public://.leading-period.txt'),
], t('Save'));
$next_fid = $this->getLastFileId();
$this->assertGreaterThan($last_fid_prior, $next_fid);
$file = File::load($next_fid);
$this->assertEquals('leading-period.txt', $file->getFilename());
}

/**
* Ensure a file entity can be saved when the file does not exist on disk.
*/
Expand Down

0 comments on commit c94aa7f

Please sign in to comment.