Skip to content

Commit ae1dc51

Browse files
authored
Merge branch 'develop' into MC-41569
2 parents c80acbe + 95c01a7 commit ae1dc51

File tree

13 files changed

+314
-148
lines changed

13 files changed

+314
-148
lines changed

app/code/Magento/PageBuilder/Controller/Adminhtml/ContentType/Image/Upload.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
use Magento\Framework\Filesystem;
1212

1313
/**
14-
* Class Upload
14+
* Image upload controller
15+
*
16+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1517
*/
1618
class Upload extends \Magento\Backend\App\Action implements HttpPostActionInterface
1719
{
@@ -115,7 +117,7 @@ public function execute()
115117
}
116118

117119
$result = $fileUploader->save($this->getUploadDir());
118-
$baseUrl = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
120+
$baseUrl = $this->_backendUrl->getBaseUrl(['_type' => \Magento\Framework\UrlInterface::URL_TYPE_MEDIA]);
119121
$result['id'] = $this->cmsWysiwygImages->idEncode($result['file']);
120122
$result['url'] = $baseUrl . $this->getFilePath(self::UPLOAD_DIR, $result['file']);
121123
} catch (\Exception $e) {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,13 @@ function ($errorNumber, $errorString) {
173173
$string = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8');
174174
try {
175175
libxml_use_internal_errors(true);
176+
// LIBXML_SCHEMA_CREATE option added according to this message
177+
// https://stackoverflow.com/a/66473950/773018
178+
// Its need to avoid bug described in maskScriptTags()
179+
// https://bugs.php.net/bug.php?id=52012
176180
$domDocument->loadHTML(
177-
'<html><body>' . $string . '</body></html>'
181+
'<html><body>' . $string . '</body></html>',
182+
LIBXML_SCHEMA_CREATE
178183
);
179184
libxml_clear_errors();
180185
} catch (Exception $e) {

app/code/Magento/PageBuilder/Model/Stage/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public function getConfig()
198198
'menu_sections' => $this->getMenuSections(),
199199
'content_types' => $this->getContentTypes(),
200200
'stage_config' => $this->data,
201-
'media_url' => $this->frontendUrlBuilder->getBaseUrl(['_type' => UrlInterface::URL_TYPE_MEDIA]),
201+
'media_url' => $this->urlBuilder->getBaseUrl(['_type' => UrlInterface::URL_TYPE_MEDIA]),
202202
'preview_url' => $this->urlBuilder->getUrl('pagebuilder/stage/preview'),
203203
'render_url' => $this->urlBuilder->getUrl('pagebuilder/stage/render'),
204204
'template_save_url' => $this->urlBuilder->getUrl('pagebuilder/template/save'),

app/code/Magento/PageBuilder/Test/Mftf/Data/TinyMCEData.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
<data key="anchorText">Piiramatult kõnesid ja SMSe Eestis ja ELi rändluses</data>
4444
<data key="title">Piiramatult kõnesid ja SMSe Eestis ja ELi rändluses</data>
4545
</entity>
46+
<entity name="TinyMCEWidgetCMSPageLinkWithAnchorAndTitleWithSpecialCharacter" extends="TinyMCEWidgetCMSPageLink" type="pagebuilder_text_widget_property">
47+
<data key="anchorText">Terms and "Conditions"</data>
48+
<data key="title">Privacy and "Cookie" Policy</data>
49+
</entity>
4650
<entity name="PageBuilderTextArea_WidgetCMSPageLink" type="pagebuilder_text_widget_property">
4751
<data key="widgetType">Magento\Cms\Block\Widget\Page\Link</data>
4852
<data key="editPanelValue">{{widget type=&quot;Magento\\Cms\\Block\\Widget\\Page\\Link&quot; template=&quot;widget/link/link_block.phtml&quot; page_id=</data>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="TextInlineWidgetEditingSpecialCharacterTest" extends="TextInlineWidgetEditingTest">
11+
<annotations>
12+
<features value="PageBuilder"/>
13+
<stories value="Text"/>
14+
<title value="Edit widget inline with special characters in WYSIWYG and see on storefront"/>
15+
<description value="Verify that user is able to add widget into Text Content Type and see it on storefront"/>
16+
<severity value="MAJOR"/>
17+
<useCaseId value="MC-41442"/>
18+
<testCaseId value="MC-41793"/>
19+
<group value="pagebuilder"/>
20+
<group value="pagebuilder-text"/>
21+
</annotations>
22+
<actionGroup ref="AddPageLinkWidgetToTinyMCEWithAnchorAndTitleActionGroup" stepKey="addPageLinkWidgetToTinyMCE">
23+
<argument name="page" value="$$createCMSPageB.identifier$$"/>
24+
<argument name="anchor" value="{{TinyMCEWidgetCMSPageLinkWithAnchorAndTitleWithSpecialCharacter.anchorText}}"/>
25+
<argument name="title" value="{{TinyMCEWidgetCMSPageLinkWithAnchorAndTitleWithSpecialCharacter.title}}"/>
26+
</actionGroup>
27+
<assertEquals stepKey="assertAnchorTextCMSWidgetLink" message="pass">
28+
<expectedResult type="string">{{TinyMCEWidgetCMSPageLinkWithAnchorAndTitleWithSpecialCharacter.anchorText}}</expectedResult>
29+
<actualResult type="string">{$grabAnchorText}</actualResult>
30+
</assertEquals>
31+
<assertEquals stepKey="assertTitleCMSWidgetLink" message="pass">
32+
<expectedResult type="string">{{TinyMCEWidgetCMSPageLinkWithAnchorAndTitleWithSpecialCharacter.title}}</expectedResult>
33+
<actualResult type="string">{$grabTitleText}</actualResult>
34+
</assertEquals>
35+
<seeElement selector="div.block-cms-link a[href='{{_ENV.MAGENTO_BASE_URL}}$$createCMSPageB.identifier$$']" stepKey="waitForWidgetStorefront"/>
36+
<grabTextFrom selector="div.block-cms-link a" stepKey="grabAnchorTextOnStorefront"/>
37+
<grabAttributeFrom selector="div.block-cms-link a" userInput="title" stepKey="grabTitleTextOnStorefront"/>
38+
<assertEquals stepKey="assertAnchorTextCMSWidgetLinkOnStorefront">
39+
<expectedResult type="string">{{TinyMCEWidgetCMSPageLinkWithAnchorAndTitleWithSpecialCharacter.anchorText}}</expectedResult>
40+
<actualResult type="variable">grabAnchorTextOnStorefront</actualResult>
41+
</assertEquals>
42+
<assertEquals stepKey="assertTitleCMSWidgetLinkOnStorefront">
43+
<expectedResult type="string">{{TinyMCEWidgetCMSPageLinkWithAnchorAndTitleWithSpecialCharacter.title}}</expectedResult>
44+
<actualResult type="variable">grabTitleTextOnStorefront</actualResult>
45+
</assertEquals>
46+
</test>
47+
</tests>

app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type/text/preview.js

Lines changed: 1 addition & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/js/stage.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/js/utils/editor.js

Lines changed: 50 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type/text/preview.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ import delayUntil from "../../utils/delay-until";
1313
import {
1414
createBookmark,
1515
createDoubleClickEvent,
16+
escapeDoubleQuoteWithinWidgetDirective,
1617
findNodeIndex,
1718
getActiveEditor,
1819
getNodeByIndex,
1920
isWysiwygSupported,
2021
lockImageSize,
2122
moveToBookmark,
23+
replaceDoubleQuoteWithSingleQuoteWithinVariableDirective,
2224
unlockImageSize,
2325
} from "../../utils/editor";
2426
import WysiwygFactory from "../../wysiwyg/factory";
@@ -307,12 +309,10 @@ export default class Preview extends BasePreview {
307309
super.bindEvents();
308310

309311
this.contentType.dataStore.subscribe((state: DataObject) => {
310-
// Find html elements which attributes contain magento variables directives
311-
const sanitizedContent = state.content.replace(/<([a-z0-9\-\_]+)([^>]+?[a-z0-9\-\_]+="[^"]*?\{\{.+?\}\}.*?".*?)>/gi, (match1: string, tag: string, attributes: string) => {
312-
// Replace double quote with single quote within magento variable directive
313-
const sanitizedAttributes = attributes.replace(/\{\{[^\{\}]+\}\}/gi, (match2: string) => match2.replace(/"/g, "'"));
314-
return "<" + tag + sanitizedAttributes + ">";
315-
});
312+
const sanitizedContent = replaceDoubleQuoteWithSingleQuoteWithinVariableDirective(
313+
escapeDoubleQuoteWithinWidgetDirective(state.content),
314+
);
315+
316316
if (sanitizedContent !== state.content) {
317317
state.content = sanitizedContent;
318318
}

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/stage.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ import Render from "./master-format/render";
1919
import PageBuilderInterface from "./page-builder.types";
2020
import buildStage from "./stage-builder";
2121
import {StageUpdateAfterParamsInterface} from "./stage-events.types";
22+
import {
23+
escapeDoubleQuoteWithinWidgetDirective,
24+
unescapeDoubleQuoteWithinWidgetDirective,
25+
} from "./utils/editor";
2226
import deferred, {DeferredInterface} from "./utils/promise-deferred";
2327

2428
export default class Stage {
@@ -53,7 +57,7 @@ export default class Stage {
5357
.then((renderedOutput: string) => {
5458
if (this.lastRenderId === renderId) {
5559
events.trigger(`stage:${ this.id }:masterFormatRenderAfter`, {
56-
value: renderedOutput,
60+
value: unescapeDoubleQuoteWithinWidgetDirective(renderedOutput),
5761
});
5862
this.renderingLocks.forEach((lock) => {
5963
lock.resolve(renderedOutput);
@@ -85,7 +89,7 @@ export default class Stage {
8589

8690
// Wait for the stage to be built alongside the stage being rendered
8791
Promise.all([
88-
buildStage(this, this.pageBuilder.initialValue),
92+
buildStage(this, escapeDoubleQuoteWithinWidgetDirective(this.pageBuilder.initialValue)),
8993
this.afterRenderDeferred.promise,
9094
]).then(this.ready.bind(this)).catch((error) => {
9195
console.error(error);

0 commit comments

Comments
 (0)