Skip to content

Commit

Permalink
Merge pull request #1386 from sun/xml-load-strict
Browse files Browse the repository at this point in the history
Limit strict error handling in XML::load() to configuration
  • Loading branch information
whatthejeff committed Aug 13, 2014
2 parents e50a0c4 + fb7caed commit 2f15988
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Util/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class PHPUnit_Util_Configuration
protected function __construct($filename)
{
$this->filename = $filename;
$this->document = PHPUnit_Util_XML::loadFile($filename, false, true);
$this->document = PHPUnit_Util_XML::loadFile($filename, false, true, true);
$this->xpath = new DOMXPath($this->document);
}

Expand Down
10 changes: 6 additions & 4 deletions src/Util/XML.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ public static function prepareString($string)
* @param string $filename
* @param boolean $isHtml
* @param boolean $xinclude
* @param boolean $strict
* @return DOMDocument
* @since Method available since Release 3.3.0
*/
public static function loadFile($filename, $isHtml = false, $xinclude = false)
public static function loadFile($filename, $isHtml = false, $xinclude = false, $strict = false)
{
$reporting = error_reporting(0);
$contents = file_get_contents($filename);
Expand All @@ -102,7 +103,7 @@ public static function loadFile($filename, $isHtml = false, $xinclude = false)
);
}

return self::load($contents, $isHtml, $filename, $xinclude);
return self::load($contents, $isHtml, $filename, $xinclude, $strict);
}

/**
Expand All @@ -123,13 +124,14 @@ public static function loadFile($filename, $isHtml = false, $xinclude = false)
* @param boolean $isHtml
* @param string $filename
* @param boolean $xinclude
* @param boolean $strict
* @return DOMDocument
* @since Method available since Release 3.3.0
* @author Mike Naberezny <[email protected]>
* @author Derek DeVries <[email protected]>
* @author Tobias Schlitt <[email protected]>
*/
public static function load($actual, $isHtml = false, $filename = '', $xinclude = false)
public static function load($actual, $isHtml = false, $filename = '', $xinclude = false, $strict = false)
{
if ($actual instanceof DOMDocument) {
return $actual;
Expand Down Expand Up @@ -173,7 +175,7 @@ public static function load($actual, $isHtml = false, $filename = '', $xinclude
chdir($cwd);
}

if ($loaded === false || $message !== '') {
if ($loaded === false || ($strict && $message !== '')) {
if ($filename !== '') {
throw new PHPUnit_Framework_Exception(
sprintf(
Expand Down

0 comments on commit 2f15988

Please sign in to comment.