Skip to content

Commit 341b54b

Browse files
committed
Remove Filename Normalization in Delete Controller
Filenames are normalized when saving to the server via the uploader. https://github.com/magento/magento2/blob/241271e8417c4264d44682169aa2032e955d6942/lib/internal/Magento/Framework/File/Uploader.php#L391-L407 This normalization was added to the admin delete controller in 2.2.0 09d662e#diff-7c65d1bd4c41efed1d26ddf72f15aa91R62 This change prevents admin users from deleting CMS images not conforming to the uploader normalization. For instance an image on the server named ` - .jpg` would have it's name normalized to ` _ .jpg` in the delete controller which causes the deletion to fail. Fixes magento/adobe-stock-integration#889
1 parent f9a8884 commit 341b54b

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images/DeleteFiles.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function execute()
7979
/** @var \Magento\Framework\Filesystem $filesystem */
8080
$filesystem = $this->_objectManager->get(\Magento\Framework\Filesystem::class);
8181
$dir = $filesystem->getDirectoryRead(DirectoryList::MEDIA);
82-
$filePath = $path . '/' . \Magento\Framework\File\Uploader::getCorrectFileName($file);
82+
$filePath = $path . '/' . $file;
8383
if ($dir->isFile($dir->getRelativePath($filePath)) && !preg_match('#.htaccess#', $file)) {
8484
$this->getStorage()->deleteFile($filePath);
8585
}

dev/tests/integration/testsuite/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images/DeleteFilesTest.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,43 @@ protected function setUp()
7575
* Execute method with correct directory path and file name to check that files under WYSIWYG media directory
7676
* can be removed.
7777
*
78+
* @param string $filename
7879
* @return void
80+
* @dataProvider executeDataProvider
7981
*/
80-
public function testExecute()
82+
public function testExecute(string $filename)
8183
{
84+
$filePath = $this->fullDirectoryPath . DIRECTORY_SEPARATOR . $filename;
85+
$fixtureDir = realpath(__DIR__ . '/../../../../../Catalog/_files');
86+
copy($fixtureDir . '/' . $this->fileName, $filePath);
87+
8288
$this->model->getRequest()->setMethod('POST')
83-
->setPostValue('files', [$this->imagesHelper->idEncode($this->fileName)]);
89+
->setPostValue('files', [$this->imagesHelper->idEncode($filename)]);
8490
$this->model->getStorage()->getSession()->setCurrentPath($this->fullDirectoryPath);
8591
$this->model->execute();
8692

8793
$this->assertFalse(
8894
$this->mediaDirectory->isExist(
89-
$this->mediaDirectory->getRelativePath($this->fullDirectoryPath . '/' . $this->fileName)
95+
$this->mediaDirectory->getRelativePath($this->fullDirectoryPath . '/' . $filename)
9096
)
9197
);
9298
}
9399

100+
/**
101+
* DataProvider for testExecute
102+
*
103+
* @return array
104+
*/
105+
public function executeDataProvider(): array
106+
{
107+
return [
108+
['magento_small_image.jpg'],
109+
['_.jpg'],
110+
[' - .jpg'],
111+
['-.jpg'],
112+
];
113+
}
114+
94115
/**
95116
* Check that htaccess file couldn't be removed via
96117
* \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\DeleteFiles::execute method

0 commit comments

Comments
 (0)