Skip to content

Commit 2324d99

Browse files
MC-30540: "CData section too big" error while accessing configurable product in backend
1 parent 06a0dd0 commit 2324d99

File tree

3 files changed

+87
-5
lines changed

3 files changed

+87
-5
lines changed

lib/internal/Magento/Framework/View/TemplateEngine/Xhtml/Template.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace Magento\Framework\View\TemplateEngine\Xhtml;
77

88
/**
9-
* Class Template
9+
* XML Template Engine
1010
*/
1111
class Template
1212
{
@@ -34,7 +34,7 @@ public function __construct(
3434
) {
3535
$this->logger = $logger;
3636
$document = new \DOMDocument(static::XML_VERSION, static::XML_ENCODING);
37-
$document->loadXML($content);
37+
$document->loadXML($content, LIBXML_PARSEHUGE);
3838
$this->templateNode = $document->documentElement;
3939
}
4040

@@ -56,9 +56,12 @@ public function getDocumentElement()
5656
*/
5757
public function append($content)
5858
{
59-
$newFragment = $this->templateNode->ownerDocument->createDocumentFragment();
60-
$newFragment->appendXML($content);
61-
$this->templateNode->appendChild($newFragment);
59+
$ownerDocument= $this->templateNode->ownerDocument;
60+
$document = new \DOMDocument();
61+
$document->loadXml($content, LIBXML_PARSEHUGE);
62+
$this->templateNode->appendChild(
63+
$ownerDocument->importNode($document->documentElement, true)
64+
);
6265
}
6366

6467
/**
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\View\Test\Unit\TemplateEngine\Xhtml;
9+
10+
use Magento\Framework\View\TemplateEngine\Xhtml\Template;
11+
use PHPUnit\Framework\TestCase;
12+
use Psr\Log\LoggerInterface;
13+
14+
/**
15+
* Test XML template engine
16+
*/
17+
class TemplateTest extends TestCase
18+
{
19+
/**
20+
* @var Template
21+
*/
22+
private $model;
23+
24+
/**
25+
* @inheritDoc
26+
*/
27+
protected function setUp()
28+
{
29+
parent::setUp();
30+
$this->model = new Template(
31+
$this->getMockForAbstractClass(LoggerInterface::class),
32+
file_get_contents(__DIR__ . '/../_files/simple.xml')
33+
);
34+
}
35+
36+
/**
37+
* Test that xml content is correctly appended to the current element
38+
*/
39+
public function testAppend()
40+
{
41+
$body = <<<HTML
42+
<body>
43+
<h1>Home Page</h1>
44+
<p>CMS homepage content goes here.</p>
45+
</body>
46+
HTML;
47+
$expected = <<<HTML
48+
<!--
49+
/**
50+
* Copyright &copy; Magento, Inc. All rights reserved.
51+
* See COPYING.txt for license details.
52+
*/
53+
--><html xmlns="http://www.w3.org/1999/xhtml">
54+
<head>
55+
<title>Home Page</title>
56+
</head>
57+
<body>
58+
<h1>Home Page</h1>
59+
<p>CMS homepage content goes here.</p>
60+
</body></html>
61+
62+
HTML;
63+
64+
$this->model->append($body);
65+
$this->assertEquals($expected, (string) $this->model);
66+
}
67+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<html xmlns="http://www.w3.org/1999/xhtml">
9+
<head>
10+
<title>Home Page</title>
11+
</head>
12+
</html>

0 commit comments

Comments
 (0)