@@ -26,16 +26,15 @@ class CmsStaticBlock implements \Magento\PageBuilder\Model\Stage\RendererInterfa
26
26
private $ widgetDirectiveRenderer ;
27
27
28
28
/**
29
- * Constructor
29
+ * CmsStaticBlock constructor.
30
30
*
31
- * @param WidgetDirective $widgetDirectiveRenderer
32
31
* @param \Magento\Cms\Model\ResourceModel\Block\CollectionFactory $blockCollectionFactory
32
+ * @param WidgetDirective $widgetDirectiveRenderer
33
33
*/
34
34
public function __construct (
35
- WidgetDirective $ widgetDirectiveRenderer ,
36
- \ Magento \ Cms \ Model \ ResourceModel \ Block \ CollectionFactory $ blockCollectionFactory
35
+ \ Magento \ Cms \ Model \ ResourceModel \ Block \ CollectionFactory $ blockCollectionFactory ,
36
+ WidgetDirective $ widgetDirectiveRenderer
37
37
) {
38
-
39
38
$ this ->blockCollectionFactory = $ blockCollectionFactory ;
40
39
$ this ->widgetDirectiveRenderer = $ widgetDirectiveRenderer ;
41
40
}
@@ -79,12 +78,28 @@ public function render(array $params): array
79
78
80
79
if ($ block ->isActive ()) {
81
80
$ directiveResult = $ this ->widgetDirectiveRenderer ->render ($ params );
82
- $ result ['content ' ] = $ directiveResult ['content ' ];
81
+ $ result ['content ' ] = $ this -> removeScriptTags ( $ directiveResult ['content ' ]) ;
83
82
$ result ['error ' ] = $ directiveResult ['error ' ];
84
83
} else {
85
84
$ result ['error ' ] = __ ('Block disabled ' );
86
85
}
87
86
88
87
return $ result ;
89
88
}
89
+
90
+ /**
91
+ * Remove script tag from html
92
+ *
93
+ * @param string $html
94
+ * @return string
95
+ */
96
+ private function removeScriptTags (string $ html ) : string
97
+ {
98
+ $ dom = new \DOMDocument ();
99
+ $ dom ->loadHTML ($ html );
100
+ foreach (iterator_to_array ($ dom ->getElementsByTagName ('script ' )) as $ item ) {
101
+ $ item ->parentNode ->removeChild ($ item );
102
+ }
103
+ return $ dom ->saveHTML ();
104
+ }
90
105
}
0 commit comments