// If the filename has been modified, let the user know.
if($result->isRenamed()){
// Log security renames to help detect potential malicious uploads.
if($result->isSecurityRename()){
$message=t('For security reasons, your upload has been renamed to %filename.',['%filename'=>$file->getFilename()]);
}
else{
$message=t('Your upload has been renamed to %filename.',['%filename'=>$file->getFilename()]);
}
\Drupal::messenger()->addStatus($message);
\Drupal::logger('file')->notice('For security reasons, the uploaded file %original_filename has been renamed to %filename.',['%original_filename'=>$result->getOriginalFilename(),'%filename'=>$file->getFilename()]);
$this->assertSession()->responseContains('For security reasons, your upload has been renamed to <em class="placeholder">'.$this->phpFile->filename.'_.txt</em>');
$this->assertSession()->pageTextContains('File MIME type is text/plain.');
@@ -279,7 +280,6 @@ public function testHandleExtension(): void {
$this->drupalGet('file-test/upload');
$this->submitForm($edit,'Submit');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->responseContains('For security reasons, your upload has been renamed to <em class="placeholder">'.$this->phpFile->filename.'_.txt</em>');
$this->assertSession()->pageTextContains('File name is php-2.php_.txt.');
$this->assertSession()->pageTextContains('File MIME type is text/plain.');
@@ -304,7 +304,6 @@ public function testHandleDangerousFile(): void {
$this->drupalGet('file-test/upload');
$this->submitForm($edit,'Submit');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->responseContains('For security reasons, your upload has been renamed to <em class="placeholder">'.$this->phpFile->filename.'_.txt</em>');
$this->assertSession()->pageTextContains('File name is php-2.php_.txt.');
$this->assertSession()->pageTextContains('File MIME type is text/plain.');