Skip to content

Commit 0dce94d

Browse files
Merge pull request #1996 from magento-trigger/trigger-delivery
[trigger] Sprint 6 Bugs
2 parents 535486f + 2ed8b14 commit 0dce94d

File tree

34 files changed

+765
-507
lines changed

34 files changed

+765
-507
lines changed

app/code/Magento/Catalog/Model/Template/Filter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function viewDirective($construction)
125125
*/
126126
public function mediaDirective($construction)
127127
{
128-
$params = $this->getParameters($construction[2]);
128+
$params = $this->getParameters(html_entity_decode($construction[2], ENT_QUOTES));
129129
return $this->_storeManager->getStore()
130130
->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . $params['url'];
131131
}

app/code/Magento/Catalog/view/frontend/web/js/storage-manager.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ define([
161161
*/
162162
initUpdateStorageDataListener: function () {
163163
_.each(this.storagesNamespace, function (name) {
164-
this[name].data.subscribe(this.updateDataHandler.bind(this, name));
164+
if (this[name].data) {
165+
this[name].data.subscribe(this.updateDataHandler.bind(this, name));
166+
}
165167
}.bind(this));
166168
},
167169

app/code/Magento/Cms/Helper/Wysiwyg/Images.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Images extends \Magento\Framework\App\Helper\AbstractHelper
2929
*
3030
* @var int
3131
*/
32-
protected $_storeId = null;
32+
protected $_storeId;
3333

3434
/**
3535
* @var \Magento\Framework\Filesystem\Directory\Write
@@ -50,23 +50,33 @@ class Images extends \Magento\Framework\App\Helper\AbstractHelper
5050
*/
5151
protected $_storeManager;
5252

53+
/**
54+
* String escaper
55+
*
56+
* @var \Magento\Framework\Escaper
57+
*/
58+
protected $escaper;
59+
5360
/**
5461
* Construct
5562
*
5663
* @param \Magento\Framework\App\Helper\Context $context
5764
* @param \Magento\Backend\Helper\Data $backendData
5865
* @param \Magento\Framework\Filesystem $filesystem
5966
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
67+
* @param \Magento\Framework\Escaper $escaper
6068
*/
6169
public function __construct(
6270
\Magento\Framework\App\Helper\Context $context,
6371
\Magento\Backend\Helper\Data $backendData,
6472
\Magento\Framework\Filesystem $filesystem,
65-
\Magento\Store\Model\StoreManagerInterface $storeManager
73+
\Magento\Store\Model\StoreManagerInterface $storeManager,
74+
\Magento\Framework\Escaper $escaper
6675
) {
6776
parent::__construct($context);
6877
$this->_backendData = $backendData;
6978
$this->_storeManager = $storeManager;
79+
$this->escaper = $escaper;
7080

7181
$this->_directory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
7282
$this->_directory->create(\Magento\Cms\Model\Wysiwyg\Config::IMAGE_DIRECTORY);
@@ -148,7 +158,7 @@ public function convertIdToPath($id)
148158
*/
149159
public function isUsingStaticUrlsAllowed()
150160
{
151-
$checkResult = new \StdClass();
161+
$checkResult = (object) [];
152162
$checkResult->isAllowed = false;
153163
$this->_eventManager->dispatch(
154164
'cms_wysiwyg_images_static_urls_allowed',
@@ -166,15 +176,16 @@ public function isUsingStaticUrlsAllowed()
166176
*/
167177
public function getImageHtmlDeclaration($filename, $renderAsTag = false)
168178
{
169-
$fileurl = $this->getCurrentUrl() . $filename;
179+
$fileUrl = $this->getCurrentUrl() . $filename;
170180
$mediaUrl = $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
171-
$mediaPath = str_replace($mediaUrl, '', $fileurl);
181+
$mediaPath = str_replace($mediaUrl, '', $fileUrl);
172182
$directive = sprintf('{{media url="%s"}}', $mediaPath);
173183
if ($renderAsTag) {
174-
$html = sprintf('<img src="%s" alt="" />', $this->isUsingStaticUrlsAllowed() ? $fileurl : $directive);
184+
$src = $this->isUsingStaticUrlsAllowed() ? $fileUrl : $this->escaper->escapeHtml($directive);
185+
$html = sprintf('<img src="%s" alt="" />', $src);
175186
} else {
176187
if ($this->isUsingStaticUrlsAllowed()) {
177-
$html = $fileurl; // $mediaPath;
188+
$html = $fileUrl;
178189
} else {
179190
$directive = $this->urlEncoder->encode($directive);
180191
$html = $this->_backendData->getUrl('cms/wysiwyg/directive', ['___directive' => $directive]);

app/code/Magento/Cms/Model/Template/Filter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function setUseSessionInUrl($flag)
3737
*/
3838
public function mediaDirective($construction)
3939
{
40-
$params = $this->getParameters($construction[2]);
40+
$params = $this->getParameters(html_entity_decode($construction[2], ENT_QUOTES));
4141
return $this->_storeManager->getStore()->getBaseMediaDir() . '/' . $params['url'];
4242
}
4343
}

app/code/Magento/Cms/Model/Wysiwyg/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public function getConfig($data = [])
192192
'add_variables' => true,
193193
'add_widgets' => true,
194194
'no_display' => false,
195-
'encode_directives' => true,
195+
'add_directives' => true,
196196
'width' => '100%',
197197
'height' => '500px',
198198
'plugins' => [],

app/code/Magento/Cms/Test/Unit/Helper/Wysiwyg/ImagesTest.php

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ class ImagesTest extends \PHPUnit\Framework\TestCase
6767
*/
6868
protected $backendDataMock;
6969

70+
/**
71+
* @var \Magento\Framework\Escaper|\PHPUnit_Framework_MockObject_MockObject
72+
*/
73+
protected $escaperMock;
74+
7075
/**
7176
* @var string
7277
*/
@@ -127,13 +132,16 @@ protected function setUp()
127132

128133
$this->storeMock = $this->createMock(\Magento\Store\Model\Store::class);
129134

135+
$this->escaperMock = $this->createMock(\Magento\Framework\Escaper::class);
136+
130137
$this->imagesHelper = $this->objectManager->getObject(
131138
\Magento\Cms\Helper\Wysiwyg\Images::class,
132139
[
133140
'context' => $this->contextMock,
134141
'filesystem' => $this->filesystemMock,
135142
'storeManager' => $this->storeManagerMock,
136-
'backendData' => $this->backendDataMock
143+
'backendData' => $this->backendDataMock,
144+
'escaper' => $this->escaperMock,
137145
]
138146
);
139147
}
@@ -151,6 +159,7 @@ protected function tearDown()
151159
$this->requestMock = null;
152160
$this->urlEncoderMock = null;
153161
$this->backendDataMock = null;
162+
$this->escaperMock = null;
154163
}
155164

156165
/**
@@ -413,20 +422,38 @@ public function testGetCurrentUrl()
413422
* @param string $baseUrl
414423
* @param string $fileName
415424
* @param bool $isUsingStaticUrls
425+
* @param string|null $escapedValue
416426
* @param string $expectedHtml
417427
* @dataProvider providerGetImageHtmlDeclarationRenderingAsTag
418428
*/
419-
public function testGetImageHtmlDeclarationRenderingAsTag($baseUrl, $fileName, $isUsingStaticUrls, $expectedHtml)
420-
{
421-
$this->generalSettingsGetImageHtmlDeclaration($baseUrl, $isUsingStaticUrls);
429+
public function testGetImageHtmlDeclarationRenderingAsTag(
430+
$baseUrl,
431+
$fileName,
432+
$isUsingStaticUrls,
433+
$escapedValue,
434+
$expectedHtml
435+
) {
436+
$this->generalSettingsGetImageHtmlDeclaration($baseUrl, $isUsingStaticUrls, $escapedValue);
422437
$this->assertEquals($expectedHtml, $this->imagesHelper->getImageHtmlDeclaration($fileName, true));
423438
}
424439

425440
public function providerGetImageHtmlDeclarationRenderingAsTag()
426441
{
427442
return [
428-
['http://localhost', 'test.png', true, '<img src="http://localhost/test.png" alt="" />'],
429-
['http://localhost', 'test.png', false, '<img src="{{media url="/test.png"}}" alt="" />']
443+
[
444+
'http://localhost',
445+
'test.png',
446+
true,
447+
null,
448+
'<img src="http://localhost/test.png" alt="" />'
449+
],
450+
[
451+
'http://localhost',
452+
'test.png',
453+
false,
454+
'{{media url=&quot;/test.png&quot;}}',
455+
'<img src="{{media url=&quot;/test.png&quot;}}" alt="" />'
456+
]
430457
];
431458
}
432459

@@ -467,8 +494,9 @@ public function providerGetImageHtmlDeclaration()
467494
/**
468495
* @param string $baseUrl
469496
* @param bool $isUsingStaticUrls
497+
* @param string|null $escapedValue
470498
*/
471-
protected function generalSettingsGetImageHtmlDeclaration($baseUrl, $isUsingStaticUrls)
499+
protected function generalSettingsGetImageHtmlDeclaration($baseUrl, $isUsingStaticUrls, $escapedValue = null)
472500
{
473501
$storeId = 1;
474502
$this->imagesHelper->setStoreId($storeId);
@@ -481,6 +509,10 @@ protected function generalSettingsGetImageHtmlDeclaration($baseUrl, $isUsingStat
481509
->method('getStore')
482510
->willReturn($this->storeMock);
483511

512+
if ($escapedValue) {
513+
$this->escaperMock->expects($this->once())->method('escapeHtml')->willReturn($escapedValue);
514+
}
515+
484516
$this->generalSettingsIsUsingStaticUrlsAllowed($isUsingStaticUrls);
485517
}
486518
}

app/code/Magento/Cms/Test/Unit/Model/Template/FilterTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,20 @@ public function testMediaDirective()
6262
->willReturn($baseMediaDir);
6363
$this->assertEquals($expectedResult, $this->filter->mediaDirective($construction));
6464
}
65+
66+
public function testMediaDirectiveWithEncodedQuotes()
67+
{
68+
$baseMediaDir = 'pub/media';
69+
$construction = [
70+
'{{media url=&quot;wysiwyg/image.jpg&quot;}}',
71+
'media',
72+
' url=&quot;wysiwyg/image.jpg&quot;'
73+
];
74+
$expectedResult = 'pub/media/wysiwyg/image.jpg';
75+
76+
$this->storeMock->expects($this->once())
77+
->method('getBaseMediaDir')
78+
->willReturn($baseMediaDir);
79+
$this->assertEquals($expectedResult, $this->filter->mediaDirective($construction));
80+
}
6581
}

app/code/Magento/Email/Model/Template/Filter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ public function viewDirective($construction)
516516
*/
517517
public function mediaDirective($construction)
518518
{
519-
$params = $this->getParameters($construction[2]);
519+
$params = $this->getParameters(html_entity_decode($construction[2], ENT_QUOTES));
520520
return $this->_storeManager->getStore()
521521
->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . $params['url'];
522522
}

0 commit comments

Comments
 (0)