From 7f0f260d3110a055ca1f8fa4886e766dd303b6c1 Mon Sep 17 00:00:00 2001 From: Alexander Steshuk Date: Mon, 6 Jul 2020 15:37:39 +0300 Subject: [PATCH] magento2/issues/12087: Changes for Widget class. --- app/code/Magento/Widget/Model/Widget.php | 39 ++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/app/code/Magento/Widget/Model/Widget.php b/app/code/Magento/Widget/Model/Widget.php index d07e84186b2c9..bb6c0f22fefdf 100644 --- a/app/code/Magento/Widget/Model/Widget.php +++ b/app/code/Magento/Widget/Model/Widget.php @@ -304,6 +304,8 @@ public function getWidgetDeclaration($type, $params = [], $asIs = true) if ($name == 'conditions') { $name = 'conditions_encoded'; $value = $this->conditionsHelper->encode($value); + } elseif ($this->isTextType($widget, $name)) { + $value = $this->encodeReservedChars($value); } elseif (is_array($value)) { $value = implode(',', $value); } elseif (trim($value) == '') { @@ -456,4 +458,41 @@ protected function sortParameters($firstElement, $secondElement) $bOrder = (int)$secondElement->getData('sort_order'); return $aOrder < $bOrder ? -1 : ($aOrder > $bOrder ? 1 : 0); } + + /** + * @param $string + * @return string|string[] + */ + private function encodeReservedChars($string) + { + $map = [ + '{' => urlencode('{'), + '}' => urlencode('}') + ]; + + return str_replace( + array_keys($map), + array_values($map), + $string + ); + } + + /** + * @param $widget + * @param $name + * @return bool + */ + private function isTextType($widget, $name) + { + $parameters = $widget->getParameters(); + + if (isset($parameters[$name]) && is_object($parameters[$name])) { + $type = $parameters[$name]->getType(); + if ($type == 'text') { + return true; + } + } + + return false; + } }