Skip to content

Commit a8222e4

Browse files
committed
AC-9883: Fix Catalog System Config
1 parent 177ef17 commit a8222e4

File tree

4 files changed

+18
-29
lines changed

4 files changed

+18
-29
lines changed

app/code/Magento/Config/Model/Config/Backend/File.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,12 @@ public function beforeSave()
9696
if (!empty($file)) {
9797
$uploadDir = $this->_getUploadDir();
9898
try {
99-
// sanitize filename
100-
$fileName = strtolower(
101-
preg_replace(
102-
['#[\\s-]+#', '#[^A-Za-z0-9._ -]+#'],
103-
['-', ''],
104-
$file['name']
105-
)
106-
);
10799
/** @var Uploader $uploader */
108100
$uploader = $this->_uploaderFactory->create(['fileId' => $file]);
109101
$uploader->setAllowedExtensions($this->_getAllowedExtensions());
110102
$uploader->setAllowRenameFiles(true);
111103
$uploader->addValidateCallback('size', $this, 'validateMaxSize');
112-
$result = $uploader->save($uploadDir, $fileName);
104+
$result = $uploader->save($uploadDir);
113105
} catch (Exception $e) {
114106
throw new LocalizedException(__('%1', $e->getMessage()));
115107
}
@@ -287,7 +279,7 @@ protected function _getAllowedExtensions()
287279
private function setValueAfterValidation(string $value): void
288280
{
289281
// avoid intercepting value
290-
if (!preg_match('/^[A-Za-z0-9._\/ -]*$/', $value)) {
282+
if (preg_match('/[^a-z0-9_\\-\\.]+/i', $value)) {
291283
throw new LocalizedException(__('Invalid file name'));
292284
}
293285

app/code/Magento/Config/Test/Unit/Model/Config/Backend/FileTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function testBeforeSave()
152152
->willReturn($this->uploaderMock);
153153
$this->uploaderMock->expects($this->once())
154154
->method('save')
155-
->with($uploadDir . '/' . $scope . '/' . $scopeId, $name)
155+
->with($uploadDir . '/' . $scope . '/' . $scopeId)
156156
->willReturn($result);
157157

158158
$this->assertEquals($this->model, $this->model->beforeSave());
@@ -197,7 +197,7 @@ public function testBeforeWithoutRequest()
197197
->willReturn($this->uploaderMock);
198198
$this->uploaderMock->expects($this->once())
199199
->method('save')
200-
->with($uploadDir, $name)
200+
->with($uploadDir)
201201
->willReturn($result);
202202

203203
$this->assertEquals($this->model, $this->model->beforeSave());
@@ -300,7 +300,7 @@ public function testBeforeSaveWithException()
300300
->willReturn($this->uploaderMock);
301301
$this->uploaderMock->expects($this->once())
302302
->method('save')
303-
->with($uploadDir, $name)
303+
->with($uploadDir)
304304
->willThrowException(new \Exception($exception));
305305

306306
$this->model->beforeSave();

app/code/Magento/Config/Test/Unit/Model/Config/Backend/Image/LogoTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected function setUp(): void
5656
->willReturn($this->uploaderMock);
5757
$this->requestDataMock = $this
5858
->getMockBuilder(RequestDataInterface::class)
59-
->setMethods(['getTmpName', 'getName'])
59+
->setMethods(['getTmpName'])
6060
->getMockForAbstractClass();
6161
$mediaDirectoryMock = $this->getMockBuilder(WriteInterface::class)
6262
->disableOriginalConstructor()
@@ -83,9 +83,6 @@ public function testBeforeSave()
8383
$this->requestDataMock->expects($this->once())
8484
->method('getTmpName')
8585
->willReturn('/tmp/val');
86-
$this->requestDataMock->expects($this->once())
87-
->method('getName')
88-
->willReturn('filename');
8986
$this->uploaderMock->expects($this->once())
9087
->method('setAllowedExtensions')
9188
->with(['jpg', 'jpeg', 'gif', 'png']);

lib/internal/Magento/Framework/Data/Form/Element/Image.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
use Magento\Framework\App\ObjectManager;
1111
use Magento\Framework\Escaper;
12-
use Magento\Framework\Exception\LocalizedException;
1312
use Magento\Framework\Math\Random;
1413
use Magento\Framework\UrlInterface;
1514
use Magento\Framework\View\Helper\SecureHtmlRenderer;
@@ -67,33 +66,35 @@ public function __construct(
6766
* Return element html code
6867
*
6968
* @return string
70-
* @throws LocalizedException
7169
*/
7270
public function getElementHtml()
7371
{
7472
$html = '';
7573

76-
if ((string)$this->getEscapedValue()) {
74+
if ((string)$this->getValue()) {
7775
$url = $this->_getUrl();
7876

7977
if (!preg_match("/^http\:\/\/|https\:\/\//", $url)) {
8078
$url = $this->_urlBuilder->getBaseUrl(['_type' => UrlInterface::URL_TYPE_MEDIA]) . $url;
8179
}
8280

8381
$linkId = 'linkId' .$this->random->getRandomString(8);
84-
$html = '<a previewlinkid="' .$linkId .'" href="' .
85-
$url . '" ' .
82+
$html = '<a previewlinkid="' .$linkId .'" href="' .
83+
$url .
84+
'" ' .
8685
$this->_getUiId(
8786
'link'
8887
) .
8988
'>' .
90-
'<img src="' . $url . '" id="' .
89+
'<img src="' .
90+
$url .
91+
'" id="' .
9192
$this->getHtmlId() .
9293
'_image" title="' .
93-
$this->getEscapedValue() .
94+
$this->getValue() .
9495
'"' .
9596
' alt="' .
96-
$this->getEscapedValue() .
97+
$this->getValue() .
9798
'" height="22" width="22" class="small-image-preview v-middle" ' .
9899
$this->_getUiId() .
99100
' />' .
@@ -119,7 +120,7 @@ public function getElementHtml()
119120
protected function _getDeleteCheckbox()
120121
{
121122
$html = '';
122-
if ($this->getEscapedValue()) {
123+
if ($this->getValue()) {
123124
$label = (string)new \Magento\Framework\Phrase('Delete Image');
124125
$html .= '<span class="delete-image">';
125126
$html .= '<input type="checkbox"' .
@@ -152,8 +153,7 @@ protected function _getDeleteCheckbox()
152153
*/
153154
protected function _getHiddenInput()
154155
{
155-
return '<input type="hidden" name="' . parent::getName() .
156-
'[value]" value="' . $this->getEscapedValue() . '" />';
156+
return '<input type="hidden" name="' . parent::getName() . '[value]" value="' . $this->getValue() . '" />';
157157
}
158158

159159
/**
@@ -163,7 +163,7 @@ protected function _getHiddenInput()
163163
*/
164164
protected function _getUrl()
165165
{
166-
return $this->getEscapedValue();
166+
return $this->getValue();
167167
}
168168

169169
/**

0 commit comments

Comments
 (0)