Skip to content

Commit 14320e8

Browse files
author
Hwashiang Yu
committed
MC-31362: Media folder update
- Reverted changes to model - Updated storage path check
1 parent d3cf754 commit 14320e8

File tree

4 files changed

+3
-76
lines changed

4 files changed

+3
-76
lines changed

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,6 @@ public function execute()
6060
{
6161
try {
6262
$path = $this->getStorage()->getCmsWysiwygImages()->getCurrentPath();
63-
if (!$this->directoryResolver->validatePath($path, DirectoryList::MEDIA)
64-
|| $this->directoryResolver->validateSamePath($path, DirectoryList::MEDIA)
65-
) {
66-
throw new \Magento\Framework\Exception\LocalizedException(
67-
__('Directory %1 is not under storage root path.', $path)
68-
);
69-
}
7063
$this->getStorage()->deleteDirectory($path);
7164

7265
return $this->resultRawFactory->create();

app/code/Magento/Cms/Model/Wysiwyg/Images/Storage.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,12 +765,13 @@ public function getCmsWysiwygImages()
765765
protected function _validatePath($path)
766766
{
767767
$root = $this->_sanitizePath($this->_cmsWysiwygImages->getStorageRoot());
768-
if ($root == $path) {
768+
$realPath = realpath($path);
769+
if ($root == $realPath) {
769770
throw new \Magento\Framework\Exception\LocalizedException(
770771
__('We can\'t delete root directory %1 right now.', $path)
771772
);
772773
}
773-
if (strpos($path, (string) $root) !== 0) {
774+
if (strpos($realPath, (string) $root) !== 0) {
774775
throw new \Magento\Framework\Exception\LocalizedException(
775776
__('Directory %1 is not under storage root path.', $path)
776777
);

dev/tests/integration/testsuite/Magento/Framework/App/Filesystem/DirectoryResolverTest.php

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -120,50 +120,4 @@ public function validatePathDataProvider()
120120
],
121121
];
122122
}
123-
124-
/**
125-
* @param string $path
126-
* @param string $directoryConfig
127-
* @param bool $expectation
128-
* @dataProvider validateSamePathDataProvider
129-
* @throws \Magento\Framework\Exception\FileSystemException
130-
* @magentoAppIsolation enabled
131-
* @return void
132-
*/
133-
public function testValidateSamePath($path, $directoryConfig, $expectation)
134-
{
135-
$directory = $this->filesystem
136-
->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
137-
$path = $directory->getAbsolutePath() .'/' .$path;
138-
$this->assertEquals($expectation, $this->directoryResolver->validateSamePath($path, $directoryConfig));
139-
}
140-
141-
/**
142-
* @return array
143-
*/
144-
public function validateSamePathDataProvider()
145-
{
146-
return [
147-
[
148-
'/',
149-
DirectoryList::MEDIA,
150-
true,
151-
],
152-
[
153-
'/.',
154-
DirectoryList::MEDIA,
155-
true,
156-
],
157-
[
158-
'/../../pub/media/.',
159-
DirectoryList::MEDIA,
160-
true,
161-
],
162-
[
163-
'/../../pub/',
164-
DirectoryList::MEDIA,
165-
false,
166-
],
167-
];
168-
}
169123
}

lib/internal/Magento/Framework/App/Filesystem/DirectoryResolver.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,4 @@ public function validatePath($path, $directoryConfig = DirectoryList::MEDIA)
5555

5656
return strpos($realPath, $root) === 0;
5757
}
58-
59-
/**
60-
* Validate same path.
61-
*
62-
* Gets real path for directory provided in parameters and compares it with specified root directory.
63-
* Will return TRUE if real path of provided value is root directory path and FALSE if not.
64-
* Throws the \Magento\Framework\Exception\FileSystemException in case when directory path is absent
65-
* in Directories configuration.
66-
*
67-
* @param string $path
68-
* @param string $directoryConfig
69-
* @return bool
70-
* @throws \Magento\Framework\Exception\FileSystemException
71-
*/
72-
public function validateSamePath($path, $directoryConfig = DirectoryList::MEDIA)
73-
{
74-
$root = $this->directoryList->getPath($directoryConfig);
75-
$traverseRealPath = realpath($path);
76-
77-
return $root === $traverseRealPath;
78-
}
7958
}

0 commit comments

Comments
 (0)