Skip to content

Commit 909788c

Browse files
Merge branch 'MC-39360' of https://github.com/magento-performance/magento2ce into MC-39033
2 parents a90ebab + c6e09b2 commit 909788c

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,7 +1965,7 @@ private function getAlreadyExistedImage(array $imageRow, string $columnImage, st
19651965
if (filter_var($columnImage, FILTER_VALIDATE_URL)) {
19661966
$hash = $this->getFileHash($columnImage);
19671967
} else {
1968-
$path = $importDir . DS . $columnImage;
1968+
$path = $importDir . DIRECTORY_SEPARATOR . $columnImage;
19691969
$hash = $this->isFileExists($path) ? $this->getFileHash($path) : '';
19701970
}
19711971

@@ -1991,7 +1991,7 @@ function ($exists, $file) use ($hash) {
19911991
private function addImageHashes(array &$images): void
19921992
{
19931993
$productMediaPath = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA)
1994-
->getAbsolutePath(DS . 'catalog' . DS . 'product');
1994+
->getAbsolutePath(DIRECTORY_SEPARATOR . 'catalog' . DIRECTORY_SEPARATOR . 'product');
19951995

19961996
foreach ($images as $storeId => $skus) {
19971997
foreach ($skus as $sku => $files) {
@@ -2188,7 +2188,7 @@ private function getImportDir(): string
21882188
$dirAddon = $dirConfig[DirectoryList::MEDIA][DirectoryList::PATH];
21892189

21902190
return empty($this->_parameters[Import::FIELD_NAME_IMG_FILE_DIR])
2191-
? $dirAddon . DS . $this->_mediaDirectory->getRelativePath('import')
2191+
? $dirAddon . DIRECTORY_SEPARATOR . $this->_mediaDirectory->getRelativePath('import')
21922192
: $this->_parameters[Import::FIELD_NAME_IMG_FILE_DIR];
21932193
}
21942194

app/code/Magento/MediaStorage/App/Media.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@ public function launch(): ResponseInterface
187187
$this->mediaDirectoryPath = $config->getMediaDirectory();
188188
$allowedResources = $config->getAllowedResources();
189189
$isAllowed = $this->isAllowed;
190-
if (!$isAllowed($this->relativeFileName, $allowedResources)) {
190+
$fileAbsolutePath = $this->directoryPub->getAbsolutePath($this->relativeFileName);
191+
$fileRelativePath = str_replace(rtrim($this->mediaDirectoryPath, '/') . '/', '', $fileAbsolutePath);
192+
if (!$isAllowed($fileRelativePath, $allowedResources)) {
191193
throw new LogicException('The path is not allowed: ' . $this->relativeFileName);
192194
}
193195
}

app/code/Magento/MediaStorage/Test/Unit/App/MediaTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function testProcessRequestCreatesConfigFileMediaDirectoryIsNotProvided()
118118
->method('getAbsolutePath')
119119
->with(null)
120120
->willReturn(self::MEDIA_DIRECTORY);
121-
$this->directoryPubMock->expects(self::once())
121+
$this->directoryPubMock->expects(self::exactly(2))
122122
->method('getAbsolutePath')
123123
->with(self::RELATIVE_FILE_PATH)
124124
->willReturn($filePath);
@@ -154,7 +154,7 @@ public function testProcessRequestReturnsFileIfItsProperlySynchronized(): void
154154
->method('isReadable')
155155
->with(self::RELATIVE_FILE_PATH)
156156
->willReturn(true);
157-
$this->directoryPubMock->expects(self::once())
157+
$this->directoryPubMock->expects(self::exactly(2))
158158
->method('getAbsolutePath')
159159
->with(self::RELATIVE_FILE_PATH)
160160
->willReturn($filePath);
@@ -214,10 +214,15 @@ public function testCatchException(bool $isDeveloper, int $setBodyCalls): void
214214

215215
public function testExceptionWhenIsAllowedReturnsFalse(): void
216216
{
217+
$filePath = '/absolute/path/to/test/file.png';
217218
$this->directoryMediaMock->expects(self::once())
218219
->method('getAbsolutePath')
219220
->with(null)
220221
->willReturn(self::MEDIA_DIRECTORY);
222+
$this->directoryPubMock->expects(self::once())
223+
->method('getAbsolutePath')
224+
->with(self::RELATIVE_FILE_PATH)
225+
->willReturn($filePath);
221226
$this->configMock->expects(self::once())
222227
->method('save');
223228

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ImportWithSharedImagesTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ private function updateUploader(): void
202202
$rootDirectory = $this->fileSystem->getDirectoryWrite(DirectoryList::ROOT);
203203
$destDir = $rootDirectory->getRelativePath(
204204
$this->appParams[DirectoryList::MEDIA][DirectoryList::PATH]
205-
. DS . $this->mediaConfig->getBaseMediaPath()
205+
. DIRECTORY_SEPARATOR . $this->mediaConfig->getBaseMediaPath()
206206
);
207207
$tmpDir = $rootDirectory->getRelativePath(
208208
$this->appParams[DirectoryList::MEDIA][DirectoryList::PATH]
@@ -226,7 +226,7 @@ private function moveImages(string $fileName): void
226226
$this->appParams[DirectoryList::MEDIA][DirectoryList::PATH]
227227
);
228228
$fixtureDir = realpath(__DIR__ . '/../../_files');
229-
$tmpFilePath = $rootDirectory->getAbsolutePath($tmpDir . DS . $fileName);
229+
$tmpFilePath = $rootDirectory->getAbsolutePath($tmpDir . DIRECTORY_SEPARATOR . $fileName);
230230
$this->fileDriver->createDirectory($tmpDir);
231231
$rootDirectory->getDriver()->copy(
232232
$fixtureDir . DIRECTORY_SEPARATOR . $fileName,

0 commit comments

Comments
 (0)