From 4126ab6b80bf201eb7cc67bf4cd242052869708b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Martinovi=C4=87?= Date: Fri, 26 Dec 2014 14:14:14 +0100 Subject: [PATCH 1/6] Prevent special characters finding their way into layout handle due to SKU being used. This avoids page cache issue when Varnish tries to retrieve ESI with invalid URL on product page. --- app/code/Magento/Catalog/Helper/Product/View.php | 8 +++++--- app/code/Magento/Review/Controller/Product/ListAction.php | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Catalog/Helper/Product/View.php b/app/code/Magento/Catalog/Helper/Product/View.php index 1973e8fbf0951..8b38045df59d6 100644 --- a/app/code/Magento/Catalog/Helper/Product/View.php +++ b/app/code/Magento/Catalog/Helper/Product/View.php @@ -116,24 +116,26 @@ public function initProductLayout(ResultPage $resultPage, $product, $params = nu $pageConfig->setPageLayout($settings->getPageLayout()); } + $urlSafeSku = rawurlencode($product->getSku()); + // Load default page handles and page configurations if ($params && $params->getBeforeHandles()) { foreach ($params->getBeforeHandles() as $handle) { $resultPage->addPageLayoutHandles( - ['id' => $product->getId(), 'sku' => $product->getSku(), 'type' => $product->getTypeId()], + ['id' => $product->getId(), 'sku' => $urlSafeSku, 'type' => $product->getTypeId()], $handle ); } } $resultPage->addPageLayoutHandles( - ['id' => $product->getId(), 'sku' => $product->getSku(), 'type' => $product->getTypeId()] + ['id' => $product->getId(), 'sku' => $urlSafeSku, 'type' => $product->getTypeId()] ); if ($params && $params->getAfterHandles()) { foreach ($params->getAfterHandles() as $handle) { $resultPage->addPageLayoutHandles( - ['id' => $product->getId(), 'sku' => $product->getSku(), 'type' => $product->getTypeId()], + ['id' => $product->getId(), 'sku' => $urlSafeSku, 'type' => $product->getTypeId()], $handle ); } diff --git a/app/code/Magento/Review/Controller/Product/ListAction.php b/app/code/Magento/Review/Controller/Product/ListAction.php index 9669b04f91c7c..9774547e52779 100644 --- a/app/code/Magento/Review/Controller/Product/ListAction.php +++ b/app/code/Magento/Review/Controller/Product/ListAction.php @@ -25,8 +25,10 @@ protected function _initProductLayout($product) $pageConfig->setPageLayout($product->getPageLayout()); } $update = $this->_view->getLayout()->getUpdate(); + + $urlSafeSku = rawurlencode($product->getSku()); $this->_view->addPageLayoutHandles( - ['id' => $product->getId(), 'sku' => $product->getSku(), 'type' => $product->getTypeId()] + ['id' => $product->getId(), 'sku' => $urlSafeSku, 'type' => $product->getTypeId()] ); $this->_view->loadLayoutUpdates(); From f62fc68df4ef0e2357c07b8593112127b53f8043 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Martinovi=C4=87?= Date: Mon, 29 Dec 2014 14:49:30 +0100 Subject: [PATCH 2/6] Revert current implementation for addressing Varnish/ESI special chars in layout handles issue. --- .../PageCache/Model/Observer/ProcessLayoutRenderElement.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/PageCache/Model/Observer/ProcessLayoutRenderElement.php b/app/code/Magento/PageCache/Model/Observer/ProcessLayoutRenderElement.php index fd266341f782b..159afc6e90ed4 100644 --- a/app/code/Magento/PageCache/Model/Observer/ProcessLayoutRenderElement.php +++ b/app/code/Magento/PageCache/Model/Observer/ProcessLayoutRenderElement.php @@ -37,7 +37,7 @@ protected function _wrapEsi( 'page_cache/block/esi', [ 'blocks' => json_encode([$block->getNameInLayout()]), - 'handles' => urlencode(json_encode($layout->getUpdate()->getHandles())) + 'handles' => json_encode($layout->getUpdate()->getHandles()) ] ); return sprintf('', $url); From 517cd187a0aac43b675b33664cdce24fc8b99ae4 Mon Sep 17 00:00:00 2001 From: Vinai Kopp Date: Thu, 8 Jan 2015 14:56:08 +0100 Subject: [PATCH 3/6] Make cosmetic changes to View\Page\Config\Reader\Body * Fix typo in method name * Change interpret method return value to conform with Layout\ReaderInterface --- .../Magento/Framework/View/Page/Config/Reader/Body.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/internal/Magento/Framework/View/Page/Config/Reader/Body.php b/lib/internal/Magento/Framework/View/Page/Config/Reader/Body.php index 95311e008f587..2d779eb0fb10f 100644 --- a/lib/internal/Magento/Framework/View/Page/Config/Reader/Body.php +++ b/lib/internal/Magento/Framework/View/Page/Config/Reader/Body.php @@ -63,10 +63,11 @@ public function interpret( /** @var \Magento\Framework\View\Layout\Element $element */ foreach ($bodyElement as $element) { if ($element->getName() === self::BODY_ATTRIBUTE) { - $this->setBodyAttributeTosStructure($readerContext, $element); + $this->setBodyAttributeToStructure($readerContext, $element); } } - return $this->readerPool->interpret($readerContext, $bodyElement); + $this->readerPool->interpret($readerContext, $bodyElement); + return $this; } /** @@ -76,7 +77,7 @@ public function interpret( * @param Layout\Element $element * @return $this */ - protected function setBodyAttributeTosStructure(Layout\Reader\Context $readerContext, Layout\Element $element) + protected function setBodyAttributeToStructure(Layout\Reader\Context $readerContext, Layout\Element $element) { if ($element->getAttribute('name') == PageConfig::BODY_ATTRIBUTE_CLASS) { $readerContext->getPageConfigStructure()->setBodyClass($element->getAttribute('value')); From 73288770167ae63e6f60c2e3f2847a71068d2277 Mon Sep 17 00:00:00 2001 From: Vinai Kopp Date: Thu, 8 Jan 2015 15:00:27 +0100 Subject: [PATCH 4/6] Change interpret() return value to conform with Layout\ReaderInterface --- .../Magento/Framework/View/Layout/Reader/Container.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/View/Layout/Reader/Container.php b/lib/internal/Magento/Framework/View/Layout/Reader/Container.php index cf392399edb8c..230e6bd9c6cd5 100644 --- a/lib/internal/Magento/Framework/View/Layout/Reader/Container.php +++ b/lib/internal/Magento/Framework/View/Layout/Reader/Container.php @@ -86,7 +86,8 @@ public function interpret(Context $readerContext, Layout\Element $currentElement default: break; } - return $this->readerPool->interpret($readerContext, $currentElement); + $this->readerPool->interpret($readerContext, $currentElement); + return $this; } /** From f11b1679c05d485ab3e839781ebc5482febd6cb9 Mon Sep 17 00:00:00 2001 From: Vinai Kopp Date: Thu, 8 Jan 2015 15:01:36 +0100 Subject: [PATCH 5/6] Make interpret() return value conform to interface Change View\Layout\Reader\Move::interpret() return value to conform with Layout\ReaderInterface::interpret() --- lib/internal/Magento/Framework/View/Layout/Reader/Move.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/View/Layout/Reader/Move.php b/lib/internal/Magento/Framework/View/Layout/Reader/Move.php index 9d0fe73d2b066..e9b1c6185838b 100644 --- a/lib/internal/Magento/Framework/View/Layout/Reader/Move.php +++ b/lib/internal/Magento/Framework/View/Layout/Reader/Move.php @@ -34,7 +34,7 @@ public function getSupportedNodes() public function interpret(Context $readerContext, Layout\Element $currentElement) { $this->scheduleMove($readerContext->getScheduledStructure(), $currentElement); - return false; + return $this; } /** From 27dbfa566cfa92279488e34608b70c32f2825d0f Mon Sep 17 00:00:00 2001 From: Vinai Kopp Date: Thu, 8 Jan 2015 15:04:43 +0100 Subject: [PATCH 6/6] Make interpret() conform to interface Change View\Layout\Reader\Remove::interpret() return value to conform with Layout\ReaderInterface::interpret() --- lib/internal/Magento/Framework/View/Layout/Reader/Remove.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/View/Layout/Reader/Remove.php b/lib/internal/Magento/Framework/View/Layout/Reader/Remove.php index 3d0a9522e1146..3f5cfcce00093 100644 --- a/lib/internal/Magento/Framework/View/Layout/Reader/Remove.php +++ b/lib/internal/Magento/Framework/View/Layout/Reader/Remove.php @@ -36,6 +36,6 @@ public function interpret(Context $readerContext, Layout\Element $currentElement { $scheduledStructure = $readerContext->getScheduledStructure(); $scheduledStructure->setElementToRemoveList((string)$currentElement->getAttribute('name')); - return false; + return $this; } }