Skip to content

Commit debec19

Browse files
Merge pull request #8603 from magento-cia/cia-2.4.7-beta3-develop-bugfix-10262023
Cia 2.4.7 beta3 develop bugfix 10262023
2 parents 73a2819 + 5862619 commit debec19

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

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

-2
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,6 @@ public function executeDataProvider(): array
161161
['name with[ bracket.jpg'],
162162
['magento_small_image.jpg'],
163163
['_.jpg'],
164-
[' - .jpg'],
165-
['-.jpg'],
166164
];
167165
}
168166

lib/internal/Magento/Framework/Filesystem/Directory/PathValidator.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ public function validate(
5454
$actualPath = $this->driver->getRealPathSafety($path);
5555
}
5656

57-
if (mb_strpos($actualPath, $realDirectoryPath) !== 0
58-
&& rtrim($path, DIRECTORY_SEPARATOR) !== $realDirectoryPath
57+
if (preg_match('/(?:^-|\s-)/', $path)
58+
|| (
59+
mb_strpos($actualPath, $realDirectoryPath) !== 0
60+
&& rtrim($path, DIRECTORY_SEPARATOR) !== $realDirectoryPath
61+
)
5962
) {
6063
throw new ValidatorException(
6164
new Phrase(

lib/internal/Magento/Framework/Filesystem/File/Write.php

+12-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use Magento\Framework\Filesystem\DriverInterface;
1010
use Magento\Framework\Exception\FileSystemException;
11+
use Magento\Framework\Phrase;
1112

1213
class Write extends Read implements WriteInterface
1314
{
@@ -28,18 +29,22 @@ public function __construct($path, DriverInterface $driver, $mode)
2829
* Assert file existence for proper mode
2930
*
3031
* @return void
31-
* @throws \Magento\Framework\Exception\FileSystemException
32+
* @throws FileSystemException
3233
*/
3334
protected function assertValid()
3435
{
3536
$fileExists = $this->driver->isExists($this->path);
3637
$mode = $this->mode ?? '';
37-
if (!$fileExists && preg_match('/r/', $mode)) {
38+
if (preg_match('/(?:^-|\s-)/', basename($this->path))) {
39+
throw new FileSystemException(
40+
new Phrase('The filename "%1" contains invalid characters', [basename($this->path)])
41+
);
42+
} elseif (!$fileExists && preg_match('/r/', $mode)) {
3843
throw new FileSystemException(
39-
new \Magento\Framework\Phrase('The "%1" file doesn\'t exist.', [$this->path])
44+
new Phrase('The "%1" file doesn\'t exist.', [$this->path])
4045
);
4146
} elseif ($fileExists && preg_match('/x/', $mode)) {
42-
throw new FileSystemException(new \Magento\Framework\Phrase('The file "%1" already exists', [$this->path]));
47+
throw new FileSystemException(new Phrase('The file "%1" already exists', [$this->path]));
4348
}
4449
}
4550

@@ -56,7 +61,7 @@ public function write($data)
5661
return $this->driver->fileWrite($this->resource, $data);
5762
} catch (FileSystemException $e) {
5863
throw new FileSystemException(
59-
new \Magento\Framework\Phrase('Cannot write to the "%1" file. %2', [$this->path, $e->getMessage()])
64+
new Phrase('Cannot write to the "%1" file. %2', [$this->path, $e->getMessage()])
6065
);
6166
}
6267
}
@@ -76,7 +81,7 @@ public function writeCsv(array $data, $delimiter = ',', $enclosure = '"')
7681
return $this->driver->filePutCsv($this->resource, $data, $delimiter, $enclosure);
7782
} catch (FileSystemException $e) {
7883
throw new FileSystemException(
79-
new \Magento\Framework\Phrase('Cannot write to the "%1" file. %2', [$this->path, $e->getMessage()])
84+
new Phrase('Cannot write to the "%1" file. %2', [$this->path, $e->getMessage()])
8085
);
8186
}
8287
}
@@ -93,7 +98,7 @@ public function flush()
9398
return $this->driver->fileFlush($this->resource);
9499
} catch (FileSystemException $e) {
95100
throw new FileSystemException(
96-
new \Magento\Framework\Phrase('Cannot flush the "%1" file. %2', [$this->path, $e->getMessage()])
101+
new Phrase('Cannot flush the "%1" file. %2', [$this->path, $e->getMessage()])
97102
);
98103
}
99104
}

0 commit comments

Comments
 (0)