Skip to content

Add support for multiple space-separated CDATA sections in Magento\Framework\Xml\Parser #26822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions lib/internal/Magento/Framework/Xml/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public function initErrorHandler()
}

/**
* Get fresh DOMDocument instance
*
* @return \DOMDocument|null
*/
public function getDom()
Expand All @@ -56,6 +58,8 @@ public function getDom()
}

/**
* Get current DOMDocument node
*
* @return \DOMDocument
*/
protected function _getCurrentDom()
Expand All @@ -64,6 +68,8 @@ protected function _getCurrentDom()
}

/**
* Set current DOMDocument node
*
* @param \DOMDocument $node
* @return $this
*/
Expand All @@ -74,6 +80,8 @@ protected function _setCurrentDom($node)
}

/**
* Transform the XML document into an array
*
* @return array
*/
public function xmlToArray()
Expand All @@ -83,6 +91,8 @@ public function xmlToArray()
}

/**
* Transform a DOMDocument node into an array
*
* @param bool $currentNode
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
Expand Down Expand Up @@ -124,11 +134,11 @@ protected function _xmlToArray($currentNode = false)
}
break;
case XML_CDATA_SECTION_NODE:
$content = $node->nodeValue;
$content .= $node->nodeValue;
break;
case XML_TEXT_NODE:
if (trim($node->nodeValue) !== '') {
$content = $node->nodeValue;
$content .= $node->nodeValue;
}
break;
}
Expand All @@ -137,6 +147,8 @@ protected function _xmlToArray($currentNode = false)
}

/**
* Load an XML document from a file
*
* @param string $file
* @return $this
*/
Expand All @@ -147,6 +159,8 @@ public function load($file)
}

/**
* Load an XML document from string
*
* @param string $string
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function testGetXml()
'text' => ' some text ',
'trim_spaces' => '',
'cdata' => ' Some data here <strong>html</strong> tags are <i>allowed</i> ',
'multiple_cdata' => ' Some data here <strong>html</strong> tags are <i>allowed</i> ',
'zero' => '0',
'null' => null,
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<text> some text </text>
<trim_spaces> </trim_spaces>
<cdata><![CDATA[ Some data here <strong>html</strong> tags are <i>allowed</i> ]]></cdata>
<multiple_cdata><![CDATA[ Some data]]> here<![CDATA[ <strong>html</strong> tags]]> are <![CDATA[<i>allowed</i> ]]></multiple_cdata>
<zero>0</zero>
<null></null>
</nodes>
Expand Down