Skip to content

Commit

Permalink
[mms] Report XML parsing errors (Request #12164; math.parent@gmail.com).
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Nov 13, 2013
1 parent 354b7a2 commit f200f28
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
27 changes: 26 additions & 1 deletion framework/Pear/lib/Horde/Pear/Package/Xml.php
Expand Up @@ -78,8 +78,33 @@ public function __construct($xml, $factory = null)
$this->_path = $xml;
$xml = fopen($xml, 'r');
}

$old_libxml_use_errors = libxml_use_internal_errors(true);
$this->_xml = new DOMDocument('1.0', 'UTF-8');
$this->_xml->loadXML(stream_get_contents($xml));
foreach (libxml_get_errors() as $error) {
switch ($error->level) {
case LIBXML_ERR_WARNING:
$error_str = 'Warning ';
break;

case LIBXML_ERR_ERROR:
$error_str = 'Error ';
break;

case LIBXML_ERR_FATAL:
$error_str = 'Fatal error ';
break;
}

$error_str .= $error->code . ': ';
$error_str .= trim($error->message) . ' on file ';
$error_str .= $this->_path . ', line ' . $error->line . ' column ' . $error->column;
fwrite(STDERR, "$error_str\n");
}
libxml_clear_errors();
libxml_use_internal_errors($old_libxml_use_errors);

$rootNamespace = $this->_xml->lookupNamespaceUri($this->_xml->namespaceURI);
$this->_xpath = new DOMXpath($this->_xml);
if ($rootNamespace !== null) {
Expand Down Expand Up @@ -920,4 +945,4 @@ public function removeComment($node, $comment)
}
}
}
}
}
4 changes: 2 additions & 2 deletions framework/Pear/package.xml
Expand Up @@ -21,7 +21,7 @@
</stability>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
*
* [mms] Report XML parsing errors (Request #12164; math.parent@gmail.com).
</notes>
<contents>
<dir baseinstalldir="/" name="/">
Expand Down Expand Up @@ -509,7 +509,7 @@
<date>2013-10-15</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
*
* [mms] Report XML parsing errors (Request #12164; math.parent@gmail.com).
</notes>
</release>
</changelog>
Expand Down

0 comments on commit f200f28

Please sign in to comment.