Skip to content

Commit 51ec7f7

Browse files
MC-15385: Path check for images
- fix static tests
1 parent d630884 commit 51ec7f7

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ public function getFilesCollection($path, $type = null)
328328
$item->setName($item->getBasename());
329329
$item->setShortName($this->_cmsWysiwygImages->getShortFilename($item->getBasename()));
330330
$item->setUrl($this->_cmsWysiwygImages->getCurrentUrl() . $item->getBasename());
331+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
331332
$item->setSize(filesize($item->getFilename()));
332333
$item->setMimeType(\mime_content_type($item->getFilename()));
333334

@@ -338,6 +339,7 @@ public function getFilesCollection($path, $type = null)
338339
$thumbUrl = $this->_backendUrl->getUrl('cms/*/thumbnail', ['file' => $item->getId()]);
339340
}
340341

342+
// phpcs:ignore Generic.PHP.NoSilencedErrors
341343
$size = @getimagesize($item->getFilename());
342344

343345
if (is_array($size)) {
@@ -413,6 +415,7 @@ public function createDirectory($name, $path)
413415
'id' => $this->_cmsWysiwygImages->convertPathToId($newPath),
414416
];
415417
return $result;
418+
// phpcs:ignore Magento2.Exceptions.ThrowCatch
416419
} catch (\Magento\Framework\Exception\FileSystemException $e) {
417420
throw new \Magento\Framework\Exception\LocalizedException(__('We cannot create a new directory.'));
418421
}
@@ -439,6 +442,7 @@ public function deleteDirectory($path)
439442
$this->_deleteByPath($path);
440443
$path = $this->getThumbnailRoot() . $this->_getRelativePathToRoot($path);
441444
$this->_deleteByPath($path);
445+
// phpcs:ignore Magento2.Exceptions.ThrowCatch
442446
} catch (\Magento\Framework\Exception\FileSystemException $e) {
443447
throw new \Magento\Framework\Exception\LocalizedException(
444448
__('We cannot delete directory %1.', $this->_getRelativePathToRoot($path))
@@ -601,6 +605,7 @@ public function resizeFile($source, $keepRatio = true)
601605
$image->open($source);
602606
$image->keepAspectRatio($keepRatio);
603607
$image->resize($this->_resizeParameters['width'], $this->_resizeParameters['height']);
608+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
604609
$dest = $targetDir . '/' . pathinfo($source, PATHINFO_BASENAME);
605610
$image->save($dest);
606611
if ($this->_directory->isFile($this->_directory->getRelativePath($dest))) {
@@ -636,6 +641,7 @@ public function getThumbsPath($filePath = false)
636641
$thumbnailDir = $this->getThumbnailRoot();
637642

638643
if ($filePath && strpos($filePath, $mediaRootDir) === 0) {
644+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
639645
$thumbnailDir .= dirname(substr($filePath, strlen($mediaRootDir)));
640646
}
641647

@@ -686,6 +692,7 @@ public function isImage($filename)
686692
if (!$this->hasData('_image_extensions')) {
687693
$this->setData('_image_extensions', $this->getAllowedExtensions('image'));
688694
}
695+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
689696
$ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
690697
return in_array($ext, $this->_getData('_image_extensions'));
691698
}

0 commit comments

Comments
 (0)