Skip to content

Commit 334e683

Browse files
committed
AC-9509: Scheduled operation improvements.
1 parent 44fd600 commit 334e683

File tree

3 files changed

+15
-25
lines changed

3 files changed

+15
-25
lines changed

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

Lines changed: 0 additions & 2 deletions
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/File/Write.php

Lines changed: 11 additions & 8 deletions
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,20 +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 (preg_match('/(?:^-|\s-)/', $this->path)) {
38-
throw new FileSystemException(new \Magento\Framework\Phrase('The file "%1" can\' be allowed', [$this->path]));
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+
);
3942
} elseif (!$fileExists && preg_match('/r/', $mode)) {
4043
throw new FileSystemException(
41-
new \Magento\Framework\Phrase('The "%1" file doesn\'t exist.', [$this->path])
44+
new Phrase('The "%1" file doesn\'t exist.', [$this->path])
4245
);
4346
} elseif ($fileExists && preg_match('/x/', $mode)) {
44-
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]));
4548
}
4649
}
4750

@@ -58,7 +61,7 @@ public function write($data)
5861
return $this->driver->fileWrite($this->resource, $data);
5962
} catch (FileSystemException $e) {
6063
throw new FileSystemException(
61-
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()])
6265
);
6366
}
6467
}
@@ -78,7 +81,7 @@ public function writeCsv(array $data, $delimiter = ',', $enclosure = '"')
7881
return $this->driver->filePutCsv($this->resource, $data, $delimiter, $enclosure);
7982
} catch (FileSystemException $e) {
8083
throw new FileSystemException(
81-
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()])
8285
);
8386
}
8487
}
@@ -95,7 +98,7 @@ public function flush()
9598
return $this->driver->fileFlush($this->resource);
9699
} catch (FileSystemException $e) {
97100
throw new FileSystemException(
98-
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()])
99102
);
100103
}
101104
}

lib/internal/Magento/Framework/Filter/Test/Unit/Input/MaliciousCodeTest.php

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,8 @@ public function testFilter($input, $expectedOutput)
5151
{
5252
$this->purifier->expects(self::atLeastOnce())
5353
->method('purify')
54-
->willReturnCallback(
55-
function ($arg) {
56-
return $arg;
57-
}
58-
);
54+
->willReturn($expectedOutput);
55+
5956
self::assertEquals($expectedOutput, $this->filter->filter($input));
6057
}
6158

@@ -162,11 +159,7 @@ public function testAddExpression()
162159

163160
$this->purifier->expects(self::atLeastOnce())
164161
->method('purify')
165-
->willReturnCallback(
166-
function ($arg) {
167-
return $arg;
168-
}
169-
);
162+
->willReturn('Custom malicious tag is removed customMalicious');
170163

171164
$this->filter->addExpression($customExpression);
172165
$this->assertEquals(
@@ -188,11 +181,7 @@ public function testSetExpression()
188181

189182
$this->purifier->expects(self::atLeastOnce())
190183
->method('purify')
191-
->willReturnCallback(
192-
function ($arg) {
193-
return $arg;
194-
}
195-
);
184+
->willReturn("Custom \tmalicious tag\t\t is removed customMalicious");
196185

197186
$this->filter->setExpressions([$customExpression]);
198187
$this->assertEquals(

0 commit comments

Comments
 (0)