Skip to content

Commit

Permalink
XmlPlugin: Use DOMDocument error suppression to check validity
Browse files Browse the repository at this point in the history
  • Loading branch information
jnvsor committed Aug 18, 2024
1 parent 68de502 commit 0ab9ca7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Binary file modified build/kint.phar
Binary file not shown.
11 changes: 7 additions & 4 deletions src/Parser/XmlPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,24 @@ protected static function xmlToSimpleXML(string $var, ?string $parent_path): ?ar
*
* If it errors loading then we wouldn't have gotten this far in the first place.
*
* @psalm-param non-empty-string $var The XML string
* @psalm-assert non-empty-string $var
*
* @param ?string $parent_path The path to the parent, in this case the XML string
*
* @return ?array The root element DOMNode, the access path, and the root element name
*/
protected static function xmlToDOMDocument(string $var, ?string $parent_path): ?array
{
// There's no way to check validity in DOMDocument without making errors. For shame!
if (null === self::xmlToSimpleXML($var, $parent_path)) {
if ('' === $var) {
return null;
}

$xml = new DOMDocument();
$xml->loadXML($var);
$check = $xml->loadXML($var, LIBXML_NOWARNING | LIBXML_NOERROR);

if (false === $check) {
return null;
}

if ($xml->childNodes->count() > 1) {
$xml = $xml->childNodes;
Expand Down

0 comments on commit 0ab9ca7

Please sign in to comment.